How to find the standard deviation of a list or a Numpy array?

The numpy.std() function calculates the standard deviation of the numpy array or list along a given axis.

Example

import numpy as np
arr = [5,2,6,21,63]
print("Our array: ", arr) 
print("std of arr : ", np.std(arr))

We can also calculate the standard deviation across different axis such as rows or columns by specifying the axis parameter. Specifying axis = 0 means the standard deviation will be calculated along the column and axis = 1 specifies to find the standard deviation across the rows.

Example

import numpy as np  
  
arr = [[1, 17, 12, 12, 36],  
       [78, 16, 27, 70, 21], 
       [98, 45, 42, 11, 45, ]] 
     
# standard deviation along the columns
print("standard deviation of our array along the columns by setting axis = 0 : ", np.std(arr, axis = 0)) 
   
# standard deviation along the rows
print("standard deviation  of our array along the rows by setting axis = 1 : ", np.std(arr, axis = 1))