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