numpy.hypot() in Python Last Updated : 08 Mar, 2024 Comments Improve Suggest changes Like Article Like Report This mathematical function helps user to calculate hypotenuse for the right angled triangle, given its side and perpendicular. Result is equivalent to Equivalent to sqrt(x1**2 + x2**2), element-wise. Syntax : numpy.exp2(arr1, arr2[, out]) = ufunc 'hypot') : 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 : Working Python3 1== # 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("\nHypotenuse 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 2D array Python3 1== # Python3 program explaining # hypot() function import numpy as np leg1 = np.random.rand(3, 4) print ("leg1 array : \n", leg1) leg2 = np.ones((3, 4)) print ("leg2 array : \n", leg2) result = np.hypot(leg1, leg2) print("\nHypotenuse 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]] Code 3 : Equivalent to sqrt(x1**2 + x2**2), element-wise. Python3 1== # Python3 program explaining # hypot() function import numpy as np leg1 = np.random.rand(3, 4) print ("leg1 array : \n", leg1) leg2 = np.ones((3, 4)) print ("leg2 array : \n", leg2) result = np.sqrt((leg1 * leg1) + (leg2 * leg2)) print("\nHypotenuse 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 ]] 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]] Comment More infoAdvertise with us Next Article numpy.hypot() in Python mohit gupta_omg :) Follow Improve Article Tags : Python Python-numpy Python numpy-Mathematical Function Practice Tags : python Similar Reads numpy.exp2() in Python numpy.exp2(array, out = None, where = True, casting = 'same_kind', order = 'K', dtype = None) : This mathematical function helps user to calculate 2**x for all x being the array elements. Parameters : array : [array_like]Input array or object whose elements, we need to test. out : [ndarray, optional 2 min read numpy.cosh() in Python The numpy.cosh() is a mathematical function that helps user to calculate hyperbolic cosine for all x(being the array elements). Equivalent to 1/2 * (np.exp(x) - np.exp(-x)) and np.cos(1j*x). Syntax : numpy.cosh(x[, out]) = ufunc 'cos') Parameters : array : [array_like] elements are in radians. 2pi R 2 min read NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read numpy.isnan() in Python The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array. Syntax :Â numpy.isnan(array [, out]) Parameters :Â array : [array_like]Input array or object whose elements, we need to test for infinity out : [ndarray, optional]Output array placed wit 2 min read numpy.sinh() in Python The numpy.sinh() is a mathematical function that helps user to calculate hyperbolic sine for all x(being the array elements). Equivalent to 1/2 * (np.exp(x) - np.exp(-x)) or -1j * np.sin(1j*x). Syntax: numpy.sinh(x[, out]) = ufunc 'sin') Parameters : array : [array_like] elements are in radians. 2pi 2 min read Python NumPy Numpy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python.Besides its obvious scientific uses, Numpy can also be used as an efficient m 6 min read numpy.sqrt() in Python numpy.sqrt() in Python is a function from the NumPy library used to compute the square root of each element in an array or a single number. It returns a new array of the same shape with the square roots of the input values. The function handles both positive and negative numbers, returning NaN for n 2 min read numpy.who function - Python numpy.who() function print the NumPy arrays in the given dictionary. Syntax : numpy.who(vardict = None) Parameters : vardict : [dict, optional] A dictionary possibly containing ndarrays. Return : Returns âNoneâ. If there is no dictionary passed in or vardict is None then returns NumPy arrays in the 1 min read numpy.base_repr() in Python numpy.base_repr(number, base=2, padding=0) function is used to return a string representation of a number in the given base system. For example, decimal number 10 is represented as 1010 in binary whereas it is represented as 12 in octal. Syntax : numpy.base_repr(number, base=2, padding=0) Parameters 3 min read numpy.roots() function - Python numpy.roots() function return the roots of a polynomial with coefficients given in p. The values in the rank-1 array p are coefficients of a polynomial. If the length of p is n+1 then the polynomial is described by: p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n] Syntax : numpy.roots(p) Parame 1 min read Like