MCPcopy Create free account
hub / github.com/numpy/numpy / nanargmin

Function nanargmin

numpy/lib/nanfunctions.py:502–554  ·  view source on GitHub ↗

Return the indices of the minimum values in the specified axis ignoring NaNs. For all-NaN slices ``ValueError`` is raised. Warning: the results cannot be trusted if a slice contains only NaNs and Infs. Parameters ---------- a : array_like Input data. axis : int,

(a, axis=None, out=None, *, keepdims=np._NoValue)

Source from the content-addressed store, hash-verified

500
501@array_function_dispatch(_nanargmin_dispatcher)
502def nanargmin(a, axis=None, out=None, *, keepdims=np._NoValue):
503 """
504 Return the indices of the minimum values in the specified axis ignoring
505 NaNs. For all-NaN slices ``ValueError`` is raised. Warning: the results
506 cannot be trusted if a slice contains only NaNs and Infs.
507
508 Parameters
509 ----------
510 a : array_like
511 Input data.
512 axis : int, optional
513 Axis along which to operate. By default flattened input is used.
514 out : array, optional
515 If provided, the result will be inserted into this array. It should
516 be of the appropriate shape and dtype.
517
518 .. versionadded:: 1.22.0
519 keepdims : bool, optional
520 If this is set to True, the axes which are reduced are left
521 in the result as dimensions with size one. With this option,
522 the result will broadcast correctly against the array.
523
524 .. versionadded:: 1.22.0
525
526 Returns
527 -------
528 index_array : ndarray
529 An array of indices or a single index value.
530
531 See Also
532 --------
533 argmin, nanargmax
534
535 Examples
536 --------
537 >>> a = np.array([[np.nan, 4], [2, 3]])
538 >>> np.argmin(a)
539 0
540 >>> np.nanargmin(a)
541 2
542 >>> np.nanargmin(a, axis=0)
543 array([1, 1])
544 >>> np.nanargmin(a, axis=1)
545 array([1, 0])
546
547 """
548 a, mask = _replace_nan(a, np.inf)
549 if mask is not None:
550 mask = np.all(mask, axis=axis)
551 if np.any(mask):
552 raise ValueError("All-NaN slice encountered")
553 res = np.argmin(a, axis=axis, out=out, keepdims=keepdims)
554 return res
555
556
557def _nanargmax_dispatcher(a, axis=None, out=None, *, keepdims=None):

Callers

nothing calls this directly

Calls 4

_replace_nanFunction · 0.85
allMethod · 0.45
anyMethod · 0.45
argminMethod · 0.45

Tested by

no test coverage detected