Numpy:zero mean data and standardization

后端 未结 4 1288
既然无缘
既然无缘 2021-02-19 19:08

I saw in tutorial (there were no further explanation) that we can process data to zero mean with x -= np.mean(x, axis=0) and normalize data with x /= np.std(x

4条回答
  •  天命终不由人
    2021-02-19 19:58

    Follow the comments in the code below

    import numpy as np
    
    # create x
    x = np.asarray([1,2,3,4], dtype=np.float64)
    
    np.mean(x) # calculates the mean of the array x
    x-np.mean(x) # this is euivalent to subtracting the mean of x from each value in x
    x-=np.mean(x) # the -= means can be read as x = x- np.mean(x)
    
    np.std(x) # this calcualtes the standard deviation of the array
    x/=np.std(x) # the /= means can be read as x = x/np.std(x)
    

提交回复
热议问题