Skip to main content

Python NumPy: Finding Square Root and Standard Deviation

Finding square root using numpy.sqrt()

 This function returns a non-negative(or positive) square root of each element of the given array.

Syntax:

numpy.sqrt([array_like])

Parameters:

It takes input array whose whose square-roots are required.

Returns: 

It returns the array which has positive square root of each element of input array. 

Example:

import numpy as np
a=np.array([[1,21,43],[65,7,80]])
print(np.sqrt(a))

Output:

[[1.         4.58257569 6.55743852]
 [8.06225775 2.64575131 8.94427191]]

Finding standard deviation using numpy.std():

It is used to compute the standard deviation of the array elements along the specified axis. Standard Deviation is used to measure that how the spread of data distribution is in the given array.

Syntax:

numpy.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=
<class numpy._globals._NoValue>) 

Parameters:

  1. a: The input array whose elements are used to calculate the standard deviation.
  2. axis: It is optional.The axis along which we want to calculate the standard deviation.
  3. dtype: It defines the data type. It is used to calculate the standard deviation.
  4. out: It is used to define the output array in which the result is to be placed. 
  5. ddof: Delta Degrees of Freedom,This N-ddof divisor is used in calculations, where N represent the number of elements. It is by default 0.
  6. keepdims:  It is optional. When the value is true.It will leave the reduced axis as dimensions with size one in the resultant.

Returns:

It returns a new array which has the standard deviation. If out is None,then it will return the output array’s reference.

Example:

import numpy as np
a=np.array([[1,12,34],[56,70,8]])
print(np.std(a))

Output: 25.628217955128203

Submitted by devanshi.srivastava on August 9, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.