In the following examples, the np.size()
function from NumPy shows the number of data items of an array, and the np.std()
function is used to calculate standard deviation:
>>>import numpy as np >>>x= np.array([[1,2,3],[3,4,6]]) # 2 by 3 matrix >>>np.size(x) # number of data items 6 >>>np.size(x,1) # show number of columns 3 >>>np.std(x) 1.5723301886761005 >>>np.std(x,1) Array([ 0.81649658, 1.24721913] >>>total=x.sum() # attention to the format >>>z=np.random.rand(50) #50 random obs from [0.0, 1) >>>y=np.random.normal(size=100) # from standard normal >>>r=np.array(range(0,100),float)/100 # from 0, .01,to .99
Compared with a Python array, a NumPy array is a contiguous piece of memory that is passed directly to LAPACK, which is a software library for numerical linear algebra under the hood, so...