`torch.max` with equivalent implementation for numpy Args: x: array/tensor. Returns: the maximum of x.
(x: NdarrayTensor, dim: int | tuple | None = None, **kwargs)
| 459 | |
| 460 | |
| 461 | def max(x: NdarrayTensor, dim: int | tuple | None = None, **kwargs) -> NdarrayTensor: |
| 462 | """`torch.max` with equivalent implementation for numpy |
| 463 | |
| 464 | Args: |
| 465 | x: array/tensor. |
| 466 | |
| 467 | Returns: |
| 468 | the maximum of x. |
| 469 | |
| 470 | """ |
| 471 | |
| 472 | ret: NdarrayTensor |
| 473 | if dim is None: |
| 474 | ret = np.max(x, **kwargs) if isinstance(x, (np.ndarray, list)) else torch.max(x, **kwargs) # type: ignore |
| 475 | else: |
| 476 | if isinstance(x, (np.ndarray, list)): |
| 477 | ret = np.max(x, axis=dim, **kwargs) |
| 478 | else: |
| 479 | ret = torch.max(x, int(dim), **kwargs) # type: ignore |
| 480 | |
| 481 | return ret[0] if isinstance(ret, tuple) else ret |
| 482 | |
| 483 | |
| 484 | def mean(x: NdarrayTensor, dim: int | tuple | None = None, **kwargs) -> NdarrayTensor: |
no outgoing calls