一些例子
>>>import numpy as np
>>>a=np.arange(12,0,-1).reshape(3,4)
>>>a
array([[12, 11, 10, 9],
[ 8, 7, 6, 5],
[ 4, 3, 2, 1]])
>>>np.argmin(a) # 最小值索引
11
>>>np.argmax(a) # 最大值索引
0
>>>np.mean(a)
6.5
>>>np.average(a)
6.5
>>>np.median(a) # 偶数个元素无中位数取中位数两边值的平均值,奇数个元素直接取中间元素的值
6.5
>>>np.cumsum(a)
array([12, 23, 33, 42, 50, 57, 63, 68, 72, 75, 77, 78]
>>>np.diff(a)
array([[-1, -1, -1],
[-1, -1, -1],
[-1, -1, -1]])
>>>np.sort(a)
array([[ 9, 10, 11, 12],
[ 5, 6, 7, 8],
[ 1, 2, 3, 4]])
>>>np.transpose(a)
array([[12, 8, 4],
[11, 7, 3],
[10, 6, 2],
[ 9, 5, 1]])
>>>a.T
array([[12, 8, 4],
[11, 7, 3],
[10, 6, 2],
[ 9, 5, 1]])
>>>np.clip(a,4,9)
array([[9, 9, 9, 9],
[8, 7, 6, 5],
[5, 5, 5, 5]]) |