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

Function nanargmax

numpy/lib/nanfunctions.py:562–615  ·  view source on GitHub ↗

Return the indices of the maximum 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 : in

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

Source from the content-addressed store, hash-verified

560
561@array_function_dispatch(_nanargmax_dispatcher)
562def nanargmax(a, axis=None, out=None, *, keepdims=np._NoValue):
563 """
564 Return the indices of the maximum values in the specified axis ignoring
565 NaNs. For all-NaN slices ``ValueError`` is raised. Warning: the
566 results cannot be trusted if a slice contains only NaNs and -Infs.
567
568
569 Parameters
570 ----------
571 a : array_like
572 Input data.
573 axis : int, optional
574 Axis along which to operate. By default flattened input is used.
575 out : array, optional
576 If provided, the result will be inserted into this array. It should
577 be of the appropriate shape and dtype.
578
579 .. versionadded:: 1.22.0
580 keepdims : bool, optional
581 If this is set to True, the axes which are reduced are left
582 in the result as dimensions with size one. With this option,
583 the result will broadcast correctly against the array.
584
585 .. versionadded:: 1.22.0
586
587 Returns
588 -------
589 index_array : ndarray
590 An array of indices or a single index value.
591
592 See Also
593 --------
594 argmax, nanargmin
595
596 Examples
597 --------
598 >>> a = np.array([[np.nan, 4], [2, 3]])
599 >>> np.argmax(a)
600 0
601 >>> np.nanargmax(a)
602 1
603 >>> np.nanargmax(a, axis=0)
604 array([1, 0])
605 >>> np.nanargmax(a, axis=1)
606 array([1, 1])
607
608 """
609 a, mask = _replace_nan(a, -np.inf)
610 if mask is not None:
611 mask = np.all(mask, axis=axis)
612 if np.any(mask):
613 raise ValueError("All-NaN slice encountered")
614 res = np.argmax(a, axis=axis, out=out, keepdims=keepdims)
615 return res
616
617
618def _nansum_dispatcher(a, axis=None, dtype=None, out=None, keepdims=None,

Callers

nothing calls this directly

Calls 4

_replace_nanFunction · 0.85
allMethod · 0.45
anyMethod · 0.45
argmaxMethod · 0.45

Tested by

no test coverage detected