首页 > 代码库 > numpy 数组的axis

numpy 数组的axis

numpy中的axis怎么理解:数组的维数,比如4*5数组,行为axis=1,列为axis=0

eg:

a = np.arange(20).reshape(4,5)
print "a:"
print a

print "maximum element in each row of a: " + str(a.max(axis=1))
print "minimum element in each column of a: " + str(a.min(axis=0))

 

a:
[[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19]]
maximum element in each row of a: [ 4 9 14 19]
minimum element in each column of a: [0 1 2 3 4]

numpy 数组的axis