代码:
x = np.arange(12).reshape(3,4)
print('整切:\n',x[:,[2,3]])# 整切:目标为整行整列
# print('索引切片:\n',x[[0,1,2],[1,2]]) 索引切片:切出的数量等于索引长度,所以维度不同会报错,
print('索引切片:\n',x[[0,1,2],[1,2,3]])
输出
整切:
[[ 2 3]
[ 6 7]
[10 11]]
索引切片:
[ 1 6 11]
代码:
x = np.arange(12).reshape(3,4)
print('整切:\n',x[:,[2,3]])# 整切:目标为整行整列
# print('索引切片:\n',x[[0,1,2],[1,2]]) 索引切片:切出的数量等于索引长度,所以维度不同会报错,
print('索引切片:\n',x[[0,1,2],[1,2,3]])
输出
整切:
[[ 2 3]
[ 6 7]
[10 11]]
索引切片:
[ 1 6 11]