MCPcopy
hub / github.com/pandas-dev/pandas / nanargmax

Function nanargmax

pandas/core/nanops.py:1128–1171  ·  view source on GitHub ↗

Parameters ---------- values : ndarray axis : int, optional skipna : bool, default True mask : ndarray[bool], optional nan-mask if known Returns ------- result : int or ndarray[int] The index/indices of max value in specified axis or -1 in the N

(
    values: np.ndarray,
    *,
    axis: AxisInt | None = None,
    skipna: bool = True,
    mask: npt.NDArray[np.bool_] | None = None,
)

Source from the content-addressed store, hash-verified

1126
1127
1128def nanargmax(
1129 values: np.ndarray,
1130 *,
1131 axis: AxisInt | None = None,
1132 skipna: bool = True,
1133 mask: npt.NDArray[np.bool_] | None = None,
1134) -> int | np.ndarray:
1135 """
1136 Parameters
1137 ----------
1138 values : ndarray
1139 axis : int, optional
1140 skipna : bool, default True
1141 mask : ndarray[bool], optional
1142 nan-mask if known
1143
1144 Returns
1145 -------
1146 result : int or ndarray[int]
1147 The index/indices of max value in specified axis or -1 in the NA case
1148
1149 Examples
1150 --------
1151 >>> from pandas.core import nanops
1152 >>> arr = np.array([1, 2, 3, np.nan, 4])
1153 >>> nanops.nanargmax(arr)
1154 np.int64(4)
1155
1156 >>> arr = np.array(range(12), dtype=np.float64).reshape(4, 3)
1157 >>> arr[2:, 2] = np.nan
1158 >>> arr
1159 array([[ 0., 1., 2.],
1160 [ 3., 4., 5.],
1161 [ 6., 7., nan],
1162 [ 9., 10., nan]])
1163 >>> nanops.nanargmax(arr, axis=1)
1164 array([2, 2, 1, 1])
1165 """
1166 values, mask = _get_values(values, True, fill_value_typ="-inf", mask=mask)
1167 result = values.argmax(axis)
1168 # error: Argument 1 to "_maybe_arg_null_out" has incompatible type "Any |
1169 # signedinteger[Any]"; expected "ndarray[Any, Any]"
1170 result = _maybe_arg_null_out(result, axis, mask, skipna) # type: ignore[arg-type]
1171 return result
1172
1173
1174def nanargmin(

Callers

nothing calls this directly

Calls 3

_get_valuesFunction · 0.85
_maybe_arg_null_outFunction · 0.85
argmaxMethod · 0.45

Tested by

no test coverage detected