案例代码如下:
#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@Author : heyw
@Contact : he_yuanwen@126.com
@Time : 2020/2/8 13:17
@Software: PyCharm
@FileName: numpy_indexSymbol.py
"""
import numpy as np
test = np.random.random((3,4,5))
print("test为\n",test)
print("\n")
print("test[:,1]为\n",test[:,1])
print("\n")
print("test[...,1]为\n",test[...,1])
print("\n")
print("test[:,1,:]为\n",test[:,1,:])
输出如下:
test为
[[[0.64275062 0.01155537 0.59854379 0.43515153 0.11517887]
[0.45379645 0.33273763 0.64681867 0.96296717 0.86828019]
[0.47480149 0.69944311 0.52491199 0.42722443 0.60872541]
[0.11681517 0.7149275 0.71927062 0.02081309 0.26383183]]
[[0.54811336 0.54153459 0.4030692 0.08086923 0.91398796]
[0.61821003 0.06968389 0.66622726 0.44132498 0.3855626 ]
[0.252149 0.04741957 0.6682169 0.54032683 0.97480844]
[0.87934921 0.41063684 0.99071229 0.9279397 0.72394113]]
[[0.58928199 0.83527366 0.10932277 0.61232461 0.95702689]
[0.20537855 0.40081702 0.64369593 0.6293745 0.03426004]
[0.05184449 0.4287514 0.15122545 0.98499028 0.86658541]
[0.91006624 0.74472196 0.03202113 0.02517913 0.37541133]]]
test[:,1]为
[[0.45379645 0.33273763 0.64681867 0.96296717 0.86828019]
[0.61821003 0.06968389 0.66622726 0.44132498 0.3855626 ]
[0.20537855 0.40081702 0.64369593 0.6293745 0.03426004]]
test[...,1]为
[[0.01155537 0.33273763 0.69944311 0.7149275 ]
[0.54153459 0.06968389 0.04741957 0.41063684]
[0.83527366 0.40081702 0.4287514 0.74472196]]
PS:test[:,1,:]与test[:,1]等同
test[:,1,:]为
[[0.45379645 0.33273763 0.64681867 0.96296717 0.86828019]
[0.61821003 0.06968389 0.66622726 0.44132498 0.3855626 ]
[0.20537855 0.40081702 0.64369593 0.6293745 0.03426004]]