我有一个矩阵mat:
array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25]])
我想知道为什么 mat[:3,1:2] 是:
array([[ 2],
[ 7],
[12]])`
但是 mat[:3,1] 是:
array([ 2, 7, 12])
请您参考如下方法:
An integer,
i, returns the same values asi:i+1except the dimensionality of the returned object is reduced by1. In particular, a selection tuple with thep-thelement an integer (and all other entries:) returns the corresponding sub-array with dimensionN - 1. IfN = 1then the returned object is an array scalar. These objects are explained in Scalars. https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html
谢谢@Kasramvd
