Python中None作为索引的作用
作者:互联网
None的作用主要是在使用None的位置新增一个维度。
a = np.arange(25).reshape(5,5)
print(a)
'''
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]
[15 16 17 18 19]
[20 21 22 23 24]]
'''
print(a[:,None])
'''
shape:5*1*5
[[[ 0 1 2 3 4]]
[[ 5 6 7 8 9]]
[[10 11 12 13 14]]
[[15 16 17 18 19]]
[[20 21 22 23 24]]]
'''
print(a[:,:,None])
'''
shape: 5*5*1
[[[ 0]
[ 1]
[ 2]
[ 3]
[ 4]]
[[ 5]
[ 6]
[ 7]
[ 8]
[ 9]]
[[10]
[11]
[12]
[13]
[14]]
[[15]
[16]
[17]
[18]
[19]]
[[20]
[21]
[22]
[23]
[24]]]
'''
标签:24,None,20,21,22,23,Python,索引 来源: https://www.cnblogs.com/sxq-blog/p/16644471.html