mygrad.amax#
- mygrad.amax(x: ArrayLike, axis: None | int | Tuple[int, ...] = None, keepdims: bool = False, *, constant: bool | None = None) Tensor #
Return the maximum of a tensor or maximum along its axes.
- Parameters:
- xArrayLike
- axisOptional[int, Tuple[int, …]]
Axis or axes along which to operate. By default, flattened input is used.
- keepdimsbool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original arr.
- constantOptional[bool]
If
True
, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e.constant.grad
will always returnNone
).Defaults to
False
for float-type data. Defaults toTrue
for integer-type data.Integer-type tensors must be constant.
- Returns:
- maxmygrad.Tensor
Maximum of a. If axis is None, the result is a 0-D tensor.
Examples
>>> import mygrad as mg >>> import numpy as np >>> a = mg.arange(4).reshape((2,2)) >>> a Tensor([[0, 1], [2, 3]]) >>> mg.amax(a) # Maximum of the flattened array Tensor(3) >>> mg.amax(a, axis=0) # Maxima along the first axis Tensor([2, 3]) >>> mg.amax(a, axis=1) # Maxima along the second axis Tensor([1, 3]) >>> b = mg.arange(5, dtype=float) >>> b[2] = np.NaN >>> mg.amax(b) Tensor(nan)