In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
%load_ext autoreload
%autoreload 2

Data Generation


In [2]:
num_samples, num_features = 10, 5

In [3]:
np.random.seed(10)
data = np.random.rand(num_samples, num_features)

Solution


In [4]:
print(data)


[[ 0.77132064  0.02075195  0.63364823  0.74880388  0.49850701]
 [ 0.22479665  0.19806286  0.76053071  0.16911084  0.08833981]
 [ 0.68535982  0.95339335  0.00394827  0.51219226  0.81262096]
 [ 0.61252607  0.72175532  0.29187607  0.91777412  0.71457578]
 [ 0.54254437  0.14217005  0.37334076  0.67413362  0.44183317]
 [ 0.43401399  0.61776698  0.51313824  0.65039718  0.60103895]
 [ 0.8052232   0.52164715  0.90864888  0.31923609  0.09045935]
 [ 0.30070006  0.11398436  0.82868133  0.04689632  0.62628715]
 [ 0.54758616  0.819287    0.19894754  0.8568503   0.35165264]
 [ 0.75464769  0.29596171  0.88393648  0.32551164  0.1650159 ]]

In [5]:
np.mean(data, axis=0)


Out[5]:
array([ 0.56787186,  0.44047807,  0.53966965,  0.52209063,  0.43903307])

In [6]:
centered_data = data - np.mean(data, axis=0)

In [7]:
std_data = centered_data / np.std(centered_data, axis=0)

In [8]:
print(std_data, "\n\n", np.mean(std_data, axis=0), "\n\n", np.std(std_data, axis=0))


[[ 1.0775774  -1.34411605  0.31525355  0.80665878  0.24128662]
 [-1.81711634 -0.77630186  0.74088404 -1.25592235 -1.42276759]
 [ 0.62228127  1.64254169 -1.797091   -0.03521894  1.51565143]
 [ 0.23651339  0.90075228 -0.83122987  1.40786459  1.11788073]
 [-0.13414844 -0.95529104 -0.55795449  0.54097769  0.01136005]
 [-0.70898541  0.56774371 -0.08900028  0.45652209  0.65726018]
 [ 1.2571441   0.25993298  1.23775021 -0.72176808 -1.4141686 ]
 [-1.41508984 -1.04555188  0.96949701 -1.69076861  0.75969247]
 [-0.10744434  1.21308427 -1.14296098  1.19109415 -0.35450368]
 [ 0.98926822 -0.46279408  1.15485183 -0.69943932 -1.11169162]] 

 [ -1.88737914e-16   5.55111512e-17  -2.22044605e-17   1.11022302e-17
   2.44249065e-16] 

 [ 1.  1.  1.  1.  1.]

In [ ]: