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