Trusted answers to developer questions

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The ** numpy.hypot() function** in Python is used to compute the hypotenuse of a given right-angled triangle’s sides. The

numpy.hypot() = sqrt[($opposite ^{2}$) + ($Adjacent^{2}$)]

```
numpy.hypot(x1, x2 /, out=None, *, where=True)
```

The `numpy.hypot()`

function takes the following parameter values:

and`x1`

: 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.`x2`

: This represents a location where the result is stored. This is an optional parameter value.`out`

: This is the condition over which the input is being broadcast. At a given location where this condition is`where`

`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.: This represents the other keyword arguments.`**kwargs`

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)

Implementing the numpy.hypot() function

**Line 1**: We import the`numpy`

module.**Lines 4–5**: We create the arrays`x1`

and`x2`

, which contain the legs of triangles.**Line 8**: We implement the`numpy.hypot()`

function on the arrays we created. We assign the result to a variable called`myarray`

.**Line 10**: We print the variable`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[($4^{2}$) + ($3^{2}$)] = sqrt(16 + 9) = sqrt(25) = 5.

RELATED TAGS

function

python

numpy

communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses