The numpy.hypot()
function in Python is used to compute the hypotenuse of a given right-angled triangle’s sides. The hypotenuse is opposite and adjacent to the other two sides of the triangle.
numpy.hypot() = sqrt[() + ()]
numpy.hypot(x1, x2 /, out=None, *, where=True)
The numpy.hypot()
function takes the following parameter values:
x1
and x2
: These represent the legs of the triangle, that is, the opposite and adjacent sides of the triangle. These two values are required for the function to work.out
: This represents a location where the result is stored. This is an optional parameter value.where
: This is the condition over which the input is being broadcast. At a given location where this condition is True
, the resulting array will be set to the ufunc result. Otherwise, the resulting array will retain its original value. This is also an optional parameter value.**kwargs
: This represents the other keyword arguments.The numpy.hypot()
function returns the hypotenuse of the given triangle(s).
import numpy as np# creating an array having the legs of trianglesx1 = np.array([4, 5])x2 = np.array([3, 12])# taking the arcsin element-wisemyarray = np.hypot(x1, x2)print(myarray)
numpy
module.x1
and x2
, which contain the legs of triangles.numpy.hypot()
function on the arrays we created. We assign the result to a variable called myarray
.myarray
to the console.In the example above, one of the given triangles has its legs (opposite and adjacent sides) as 4
and 3
.
Mathematically:
numpy.hypot(4, 3) = sqrt[() + ()] = sqrt(16 + 9) = sqrt(25) = 5.