Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

numpy.argmax() returns the index of a maximum value, not the value itself. For example, np.argmax(np.array([10, 30, 20])) returns 1, because the largest value, 30, is at zero-based index 1. Add an axis to find a maximum position in each row, column, or other slice.

What does numpy.argmax() return?

argmax() returns an integer index for a one-dimensional result, or an array of indices when it searches along an axis. It does not return the maximum values. Use np.max() (also available as np.amax()) to get those values, or index the original array with the position returned by argmax(). NumPy documents the function and its behavior in the argmax reference and the value reduction in the amax reference.

import numpy as np

a = np.array([4, 9, 2])
index = np.argmax(a)
value = a[index]

# index: 1
# value: 9

The documented signature is numpy.argmax(a, axis=None, out=None, *, keepdims=<no value>). The stable manual, checked August 18, 2026, is labeled NumPy v2.5; that label describes the manual, not necessarily the version installed in your environment.

  • a: array-like input.
  • axis: the axis along which to find maximum positions; the default, None, searches a flattened array.
  • out: optional array into which the index result is written.
  • keepdims: whether to retain the reduced axis as a dimension of length one.

Find a maximum index in a one-dimensional array

For a one-dimensional array, the result is the position of the largest element, using zero-based indexing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
a = np.array([7, 2, 9, 4])
np.argmax(a)
# 2

# a[2] is 9

If the maximum occurs more than once, argmax() returns the first occurrence:

a = np.array([7, 9, 3, 9])
np.argmax(a)
# 1

This gives one winner, not every tied position. NumPy specifies the first-occurrence behavior in its argmax documentation.

How does axis change the result?

For a two-dimensional array with shape (rows, columns), axis=0 searches down the rows, producing one row index per column. axis=1 searches across the columns, producing one column index per row. By default, the searched axis disappears from the output shape.

a = np.array([
    [10, 20, 30],
    [40, 50, 60]
])

np.argmax(a, axis=0)  # array([1, 1, 1]): winning row in each column
np.argmax(a, axis=1)  # array([2, 2]): winning column in each row

np.argmax(a, axis=0).shape  # (3,)
np.argmax(a, axis=1).shape  # (2,)

In the first result, each element is a row index: the largest value in every column is in row 1. In the second, each element is a column index: the largest value in each row is in column 2. The NumPy examples demonstrate these axis reductions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Negative axes

Negative axis numbers count backward from the final dimension. For an array of shape (2, 3, 4), axis=-1 is the last axis (equivalent to axis=2), axis=-2 is equivalent to axis=1, and axis=-3 is equivalent to axis=0. This is useful when code should operate on the final dimension regardless of how many leading dimensions an array has.

Higher-dimensional arrays

In three or more dimensions, each result still identifies a position along the selected axis; it is not a full coordinate in the original array. For example, the following array has shape (2, 2, 3):

x = np.array([
    [[0, 1, 2], [3, 4, 5]],
    [[6, 0, 1], [2, 3, 4]]
])

np.argmax(x, axis=0).shape  # (2, 3)
np.argmax(x, axis=1).shape  # (2, 3)
np.argmax(x, axis=2).shape  # (2, 2)

The output shape is the input shape with the selected axis removed. For additional multidimensional indexing patterns, see NumPy’s indexing guide.

Get maximum values using the returned indices

For row-wise maxima, use the row numbers together with the column indices returned by argmax(). Alternatively, calculate the values directly with np.max() when you do not need the positions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
scores = np.array([
    [72, 91, 84],
    [88, 79, 95],
    [90, 93, 89]
])

best_column = np.argmax(scores, axis=1)
best_scores = scores[np.arange(scores.shape[0]), best_column]

# best_column: array([1, 2, 1])
# best_scores: array([91, 95, 93])
# np.max(scores, axis=1): array([91, 95, 93])

For column-wise results, np.argmax(scores, axis=0) returns array([2, 1, 1]), the winning row in each column; np.max(scores, axis=0) returns the values array([90, 93, 95]).

Use take_along_axis() for general arrays

For N-dimensional arrays, np.take_along_axis() is a general way to select values using the index slices produced by argmax(). Keep the selected axis as a length-one dimension so the index array matches the data along that axis:

indices = np.argmax(scores, axis=1, keepdims=True)
values = np.take_along_axis(scores, indices, axis=1)

# indices: array([[1], [2], [1]])
# values:  array([[91], [95], [93]])

See NumPy’s take_along_axis reference for how it applies indices along an axis.

When should you use keepdims=True?

By default, reducing an axis removes it from the output shape. With keepdims=True, NumPy retains that axis at length one, which can make the result broadcast-compatible with the original array and is useful with take_along_axis().

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
a = np.arange(24).reshape(2, 3, 4)

np.argmax(a, axis=1).shape                 # (2, 4)
np.argmax(a, axis=1, keepdims=True).shape   # (2, 1, 4)

indices = np.argmax(a, axis=-1, keepdims=True)
max_values = np.take_along_axis(a, indices, axis=-1)

NumPy documents keepdims as added to argmax() in version 1.22.0, so check compatibility if your code must run on an older NumPy release.

Find the global maximum’s coordinates

With the default axis=None, NumPy treats a multidimensional array as flattened and returns a single flat index—not a row and column. For example, a 2-by-3 array laid out in row-major order has flat positions 0 through 5; its bottom-right element has flat index 5.

a = np.array([
    [10, 20, 30],
    [40, 50, 60]
])

flat_index = np.argmax(a)  # 5
coordinates = np.unravel_index(flat_index, a.shape)  # (1, 2)
value = a[coordinates]  # 60

np.unravel_index() converts a flat index into coordinates for the supplied shape; its default order is 'C' (row-major). The unravel_index reference documents the conversion. The same pattern works for arrays of any dimension: pass the array’s shape, then index with the returned coordinate tuple.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Find all tied maximum positions

If every location tied for the maximum matters, first get the maximum value and then collect every matching position. For a one-dimensional array, use np.flatnonzero(); for an array of any dimension, np.argwhere() returns coordinates of matches.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
a = np.array([5, 9, 2, 9, 1])

max_value = np.max(a)
all_indices = np.flatnonzero(a == max_value)
# array([1, 3])

For a multidimensional array, the corresponding pattern is np.argwhere(a == np.max(a)). Use argmax() instead when one first-occurring winner is the result you want.

Handle NaN values deliberately

If NaN should be ignored while finding a maximum position, use np.nanargmax(). It raises ValueError for a slice that is entirely NaN; NumPy also warns that results cannot be trusted when a slice contains only NaN values and negative infinity. Consult the nanargmax reference for these conditions.

a = np.array([
    [np.nan, 4],
    [2, 3]
])

np.nanargmax(a)  # 1

Choose between argmax() and nanargmax() based on what a NaN means in your data. The latter ignores missing values; it is not a universal replacement for the former.

When is the out parameter useful?

out writes the index result into a preallocated array. Its shape must match the result and its dtype must be suitable for integer indices. This is useful when code needs to control allocations or reuse an existing buffer; ordinary code can omit it for simplicity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
a = np.array([
    [10, 20, 30],
    [40, 50, 60]
])

out = np.empty(3, dtype=np.intp)
np.argmax(a, axis=0, out=out)
# out: array([1, 1, 1])

The parameter requirements are described in NumPy’s argmax reference.

Choose argmax() or a related function

Need Function or approach
One maximum index for an array or each slice along an axis np.argmax()
Maximum values, without their positions np.max() or np.amax()
Maximum index while ignoring NaNs np.nanargmax(), after accounting for all-NaN and negative-infinity caveats
Positions of all elements in sorted order np.argsort()
Partial top-k selection without fully sorting the selected values np.argpartition(); the selected portion is not necessarily ordered
Every position tied at the maximum Compare against the maximum, then use np.flatnonzero() or np.argwhere()
Convert a flattened index to multidimensional coordinates np.unravel_index()

argsort() and argpartition() are separate sorting and selection tools, not alternatives that return the same single-winner result as argmax(). NumPy lists them in its sorting, searching, and counting reference.

Check these points when a result looks wrong

  • If you expected a number from the array, use np.max() or index the array with the argmax() result.
  • For a matrix, confirm whether you want a result per column (axis=0) or per row (axis=1).
  • If axis=None was used, convert the flat index with np.unravel_index() before treating it as coordinates.
  • If ties matter, collect all matches rather than relying on the single first index returned.
  • If missing values are present, decide whether they should be ignored and whether any slice is all NaN.
  • If later operations require matching dimensions, use keepdims=True and check the resulting shape.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.