Numpy里的脚标有好几种形式,很容易混淆,按功能主要可以分为:
(1) 显示前面几行或者几列的,例如:
Obpj[:,:-1]显示前n-1列,obpj[:,:2]显示前两列(两个冒号之间必须带逗号);
Obpj[:-1:]和Obpj[:-1, :]显示前n-1行(两个冒号之间可以带逗号,可以不带);
(2) Obpj[::-1]将矩阵按行来倒序排列;
(3) Obpj[::2]从第0行开始,接着使用0+2行
import numpy as np
obj = np.arange(16)
objp = obj.reshape([4,4])
print(objp[:,:-1])
[[ 0 1 2]
[ 4 5 6]
[ 8 9 10]
[12 13 14]]
print(objp[:-1:])
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
print(objp[::-1])
[[12 13 14 15]
[ 8 9 10 11]
[ 4 5 6 7]
[ 0 1 2 3]]
print(objp[:,:3])
[[ 0 1 2]
[ 4 5 6]
[ 8 9 10]
[12 13 14]]
print(objp[:-1,:])
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]