To find the position of minima in a NumPy array in Python, you can use the numpy.argmin()
function. This function returns the indices of the minimum values along an axis.
Here's an example:
main.py223 chars11 lines
Output:
main.py43 chars3 lines
If you have a multi-dimensional array and want to find the position of the minimum value along a particular axis, you can pass the axis
parameter to argmin()
. Here's an example:
main.py310 chars11 lines
Output:
main.py81 chars3 lines
In this example, arr[min_indices, range(arr.shape[1])]
is used to extract the actual minimum values along axis 0.
gistlibby LogSnag