mindspore.numpy.hypot
- mindspore.numpy.hypot(x1, x2, dtype=None)[source]
Given the “legs” of a right triangle, returns its hypotenuse.
Equivalent to
sqrt(x1**2 + x2**2)
, element-wise. If x1 or x2 is scalar_like (i.e., unambiguously cast-able to a scalar type), it is broadcast for use with each element of the other argument. (See Examples)Note
Numpy arguments out, where, casting, order, subok, signature, and extobj are not supported. On GPU, the supported dtypes are np.float16 and np.float32. On CPU, the supported dtypes are np.float16, np.float32, and np.float64.
- Parameters
x1 (Tensor) – Leg of the triangle(s).
x2 (Tensor) – Leg of the triangle(s). If
x1.shape != x2.shape
, they must be broadcastable to a common shape (which becomes the shape of the output).dtype (
mindspore.dtype
, optional) – Defaults to None. Overrides the dtype of the output Tensor.
- Returns
Tensor or scalar, the hypotenuse of the triangle(s). This is a scalar if both x1 and x2 are scalars.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.numpy as np >>> output = np.hypot(3*np.ones((3, 3)), 4*np.ones((3, 3))) >>> print(output) [[5. 5. 5.] [5. 5. 5.] [5. 5. 5.]] >>> output = np.hypot(3*np.ones((3, 3)), np.array([4.0])) >>> print(output) [[5. 5. 5.] [5. 5. 5.] [5. 5. 5.]]