1.np.argmax(array, axis)
对array按照axis找最大的值返回其下标的numpy.ndarray
array 为二维时,axis = 0, 表示按列, axis = 1,表示按行
import numpy as np
a = np.array([[1, 5, 5, 2],
[9, 6, 2, 8],
[3, 7, 9, 1]])
b=np.argmax(a, axis=0) # 按照列
print(b)
c=np.argmax(a, axis=1) # 按照行
print(c)
[1 2 2 1]
[1 0 2]
2.np.unique()
该函数去除数组中的重复数字,并排序后输出。
3.np.prod()
m = [[[1,2],
[3,4]],
[[5,6],
[7,8]]]
print(np.prod(m, axis = 0))
[[ 5 12]
[21 32]]
print(np.prod(m, axis = 1))
[[ 3 8]
[35 48]]
print(np.prod(m, axis = 2))
[[ 2 12]
[30 56]]
print(np.prod(m, axis = -1))
[[ 2 12]
[30 56]]
axis为0,以最外层为基准,对象是[ [1,2], [3,4] ] 和 [ [5,6], [7,8] ],元素一一相乘, 两个list乘两个
axis为1,对象是 [1,2]和 [3,4],可以对应乘了, 以及 [5,6] 和[7,8],
axis为2,对象是 1,2,3,4,5,6,7,8,两两相乘