Numpy常用总结(20201214)

1、np.argmax() 

import numpy as np

a = np.array([[2.5404317e-03,1.1229481e-01, 1.9477041e-03, 4.1146163e-04, 1.3162383e-04,
  1.2035034e-01, 2.4439844e-03, 7.2189087e-01, 3.7895240e-02, 9.3566909e-05],
 [9.2819709e-01, 1.3503281e-02, 3.8306025e-05, 1.1033992e-04, 5.7097885e-04,
  7.4617583e-03, 3.3492967e-04, 4.8759781e-02, 7.4182393e-04, 2.8178137e-04]])
print(np.argmax(a))
print(np.argmax(a, axis=0)) # 竖着比较,返回行号
print(np.argmax(a, axis=1)) # 横着比较,返回列号
'''
10
[1 0 0 0 1 0 0 0 0 1]
[7 0]
'''

2、np.concatenate() 库数组拼接

import numpy as np

a = np.array([1,2,3])
b = np.array([11,22,33])
c = np.array([44,55,66])
print(np.concatenate((a,b,c), axis=0))
'''
[ 1  2  3 11 22 33 44 55 66]
'''
import numpy as np

a = np.array([[1,2,3], [4,5,6]])
b = np.array([[11,22,33], [7,8,9]])
print(np.concatenate((a,b), axis=0))
'''
[[ 1  2  3]
 [ 4  5  6]
 [11 22 33]
 [ 7  8  9]]
'''

'''
当axis=1时,
[[ 1  2  3 11 22 33]
 [ 4  5  6  7  8  9]]

'''


 

猜你喜欢

转载自blog.csdn.net/caicai0001000/article/details/110130799