numpy.sqrt() in Python Last Updated : 11 Apr, 2025 Summarize Suggest changes Share Like Article Like Report 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 negative inputs when working with real numbers.Example: Python import numpy as np a = np.array([1, 4, 9, 16, 25]) b = np.sqrt(a) print(b) Output[1. 2. 3. 4. 5.] Syntaxnumpy.sqrt() Parameters:array : [array_like] Input values whose square roots have to be determined. out : [ndarray, optional] Alternate array object in which to put the result; if provided, it must have the same shape as arr. Return Type: [ndarray] Returns the square root of the number in an array.Examples of numpy.sqrt()Example 1: Square Root of Positive IntegersThis example demonstrates how to compute the square root of an array of positive integers using numpy.sqrt(). Python import numpy as geek a = geek.sqrt([1, 4, 9, 16]) b = geek.sqrt([6, 10, 18]) print(a) print(b) Output[1. 2. 3. 4.] [2.44948974 3.16227766 4.24264069] Example 2: Square Root of Complex NumbersThis example shows how to compute the square root of complex numbers using numpy.sqrt(). Python import numpy as geek a = geek.sqrt([4, -1, -5 + 9J]) print(a) Output[2. +0.j 0. +1.j 1.62721083+2.76546833j] Example 3: Square Root of Negative Real NumbersThis example illustrates how numpy.sqrt() handles negative real numbers, which results in NaN for real number inputs. Python import numpy as geek a = geek.sqrt([-4, 5, -6]) print(a) Output[ nan 2.23606798 nan]Explanation: The code applies numpy.sqrt() to an array with negative real numbers. Since square roots of negative real numbers are undefined in the real number system, it returns NaN for those values. Advertise with us Next Article numpy.cbrt() in Python S sanjoy_62 Follow Similar Reads numpy.square() in Python numpy.square(arr, out = None, ufunc 'square') : This mathematical function helps user to calculate square value of each element in the array. Parameters : arr : [array_like] Input array or object whose elements, we need to square. Return : An array with square value of each array. Code #1 : Working 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 numpy.cbrt() in Python This mathematical function helps user to calculate cube root of x for all x being the array elements. Syntax: numpy.cbrt(arr, out = None, ufunc âcbrtâ) : Parameters : arr : [array_like] Input array or object whose elements, we need to square. Return : An array with cube root of x for all x i.e. arra 2 min read numpy.reciprocal() in Python The numpy.reciprocal() is a mathematical function that is used to calculate reciprocal of all the elements in the input array. Syntax :numpy.reciprocal(x, /, out=None, *, where=True) Parameters : x[array_like]: Input array or object whose elements needed to test. out [ndarray, optional]: A location 2 min read Python | Decimal sqrt() method Decimal#sqrt() : sqrt() is a Decimal class method which returns the Square root of a non-negative number to context precision. Syntax: Decimal.sqrt() Parameter: Decimal values Return: the Square root of a non-negative number to context precision. Code #1 : Example for sqrt() method Python3 # Python 2 min read Python | cmath.sqrt() method With the help of cmath.sqrt() method, we can find the value of square root any number by passing it to cmath.sqrt() method. Syntax : cmath.sqrt(value) Return : Return the square root of any value. Example #1 : In this example we can see that by using cmath.sqrt() method, we are able to get the value 1 min read Article Tags : Python Python-numpy Practice Tags : python Like