1. 程式人生 > >numpy 模組學習記錄五

numpy 模組學習記錄五

a
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
>>> a.sum()
36
>>> np.sum(a)
36
>>> a.mean(1)
array([ 1.,  4.,  7.])
>>> a.mean(0)
array([ 3.,  4.,  5.])
>>> a.mean(axis = 1)
array([ 1.,  4.,  7.])
>>> a.mean(axis = 0)
array([ 3.,  4.,  5.])
>>> np.mean(a,axis = 1)
array([ 1.,  4.,  7.])
>>> np.mean(a,axis = 0)
array([ 3.,  4.,  5.])
>>> np.mean(a,0)
array([ 3.,  4.,  5.])
>>> np.std(a,0)
array([ 2.44948974,  2.44948974,  2.44948974])
>>> np.std(a,1)
array([ 0.81649658,  0.81649658,  0.81649658])
>>> np.var(a)
6.666666666666667
>>> np.var(a,0)
array([ 6.,  6.,  6.])
>>> 6**0.5
2.449489742783178
>>> (2/3)**0.5
0.816496580927726
>>> a.var(1)
array([ 0.66666667,  0.66666667,  0.66666667])
>>> a.min()
0
>>> a.max()
8
>>> a.min(1)
array([0, 3, 6])
>>> a.argmin()
0
>>> a
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
>>> a.argmax()
8
>>> a[[0,2,1]]
array([[0, 1, 2],
       [6, 7, 8],
       [3, 4, 5]])
>>> a[[0,2,1]].argmax()
5
>>> a.argmax(0)
array([2, 2, 2], dtype=int64)
>>> a.argmin(1)
array([0, 0, 0], dtype=int64)
>>> a
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
>>> a.cumsum()
array([ 0,  1,  3,  6, 10, 15, 21, 28, 36], dtype=int32)
>>> a.cumprod()
array([0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32)
>>> a.sum(0)
array([ 9, 12, 15])
>>> np.cumprod(a,0)
array([[ 0,  1,  2],
       [ 0,  4, 10],
       [ 0, 28, 80]], dtype=int32)