Change language

# numpy.hypot () in Python

Parameters :

`  arr1, arr2:   [array_like]  Legs (side and perpendicular) of triangle  out:   [ndarray, optional]  Output array with result. `

Return:

` An array having hypotenuse of the right triangle. `

Code # 1: Work

 ` # Python3 program explaining ` ` # hypot () function `   ` import ` ` numpy as np ` ` `  ` leg1 ` ` = ` ` [` ` 12 ` `, ` ` 3 ` `, ` ` 4 ` `, ` ` 6 ` `] ` ` print ` ` (` ` "leg1 array:" ` ` , leg1) `   ` `  ` leg2 ` ` = ` ` [` ` 5 ` `, ` ` 4 ` ` , ` ` 3 ` `, ` ` 8 ` `] ` ` print ` ` (` `" leg2 array: "` `, leg2) ` ` `  ` result ` ` = ` ` np.hypot (leg1, leg2) ` ` print ` ` (` ` "Hypotenuse is as follows:" ` `) ` ` print ` ` (result) `

Output:

` leg1 array: [12 , 3, 4, 6] leg2 array: [5, 4, 3, 8] Hypotenuse is as follows: [13. 5. 5. 10.] `

Code # 2: Working with a 2D Array

 ` # Python3 program explaining ` ` function # hypot () `   ` import ` ` numpy as np `   ` leg1 ` ` = ` ` np.random.rand (` ` 3 ` `, ` ` 4 ` `) ` ` print ` ` (` `" leg1 array: "` `, leg1) `   ` leg2 ` ` = ` ` np.ones ((` ` 3 ` `, ` ` 4 ` `)) ` ` print ` ` (` ` "leg2 array:" ` `, leg2) `   ` result ` ` = ` ` np.hypot (leg1, leg2) ` ` print ` ` (` ` "Hypotenuse is as follows:" ` `) ` ` print ` ` (result) `

Output:

` leg1 array: [[0.57520509 0.12043366 0.50011671 0.13800957] [0.0528084 0.17827692 0.44236813 0.87758732] [0.94926413 0.47816742 0.46111934 0.63728903]] leg2 array: [[1. 1. 1. 1.] [1. 1. 1. 1.] [1. 1. 1. 1.]] Hypotenuse is as follows: [[1.15362944 1.00722603 1.11808619 1.0094784] [1.00139339 1.01576703 1.09347591 1.33047342] [1.37880469 1.10844219 1.10119528 1.18580661]] `

3: Equivalent to sqrt (x1 ** 2 + x2 ** 2), element by element.

 ` # Python3 explainer program ` ` # hypot () function `   ` import ` ` numpy as np `   ` leg1 ` ` = ` ` np.random.rand (` ` 3 ` `, ` ` 4 ` `) ` ` print ` ` (` ` "leg 1 array: "` `, leg1) ` ` `  ` leg2 ` ` = ` ` np.ones ((` ` 3 ` `, ` ` 4 ` `)) ` ` print ` ` (` ` "leg2 array:" ` `, leg2) `   ` result ` ` = ` ` sqrt-in-python/">np. sqrt ((leg1 ` ` * ` ` leg1) ` ` + ` ` (leg2 ` ` * ` ` leg2)) ` ` print ` ` (` ` "Hypotenuse is as follows:" ` `) ` ` print ` ` (result) `

Output:

` leg1 array: [[0.7015073 0.89047987 0.1595603 0.27557254] [0.67249153 0.16430312 0.70137114 0.48763522] [0.68067777 0.52154819 0.04339669 0.2239366] leg [1. 1. 1. 1.] [1. 1. 1. 1.] [1. 1. 1. 1.]] Hypotenuse is as follows: [[1.15362944 1.00722603 1.11808619 1.0094784] [1.00139339 1.01576703 1.09347591 1.33047342] [ 1.37880469 1.10844219 1.10119528 1.18580661]] `

## Shop

Learn programming in R: courses

\$FREE

Best Python online courses for 2022

\$FREE

Best laptop for Fortnite

\$399+

Best laptop for Excel

\$

Best laptop for Solidworks

\$399+

Best laptop for Roblox

\$399+

Best computer for crypto mining

\$499+

Best laptop for Sims 4

\$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries