hypot() - ( NumPy Functions )
Heading h2
Syntax
numpy.hypot(x, y, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
Example
import numpy as np
x = np.array([3, 4])
y = np.array([4, 3])
result = np.hypot(x, y)
print(result)
Output
[5. 5. ]
Explanation
The numpy.hypot()
function is used to compute the hypotenuse of a right-angled triangle given the lengths of its legs. It takes two arrays x
and y
of the same shape, and returns an array containing the hypotenuse of each corresponding triangle. Specifically, it computes the square root of the sum of the squares of the two input arrays.
Use
The numpy.hypot()
function is useful in a variety of applications, such as:
- Computing the distance between two points in Euclidean space
- Computing the magnitude of a complex number
Important Points
- The
numpy.hypot()
function takes two arraysx
andy
of the same shape, and returns an array containing the hypotenuse of each corresponding right-angled triangle - It computes the square root of the sum of the squares of the two input arrays
- The function is useful for computing the distance between two points in Euclidean space, or the magnitude of a complex number
Summary
In conclusion, the numpy.hypot()
function is a useful tool for computing the hypotenuse of a right-angled triangle given the lengths of its legs. It takes two arrays x
and y
of the same shape, and returns an array containing the hypotenuse of each corresponding triangle. It is useful in a variety of applications, such as computing distances in Euclidean space or magnitudes of complex numbers.