[英]Having trouble indexing this numpy array [Python]
So the array is called lines
and looks like this:所以这个数组叫做
lines
,看起来像这样:
All I would like to do is index the 3rd column (all values in the rows).我想做的就是索引第三列(行中的所有值)。 Which I thought would just be like this:
我以为会是这样的:
lines[:,2]
which gives me this error: lines[:,2]
这给了我这个错误:
IndexError: index 1 is out of bounds for axis 1 with size 1
So when I check the shape lines.shape
I get:所以当我检查形状
lines.shape
我得到:
(1, 4)
I'm not sure what the issue is?我不确定是什么问题?
You used nested list so If you want to get list您使用了嵌套列表,所以如果您想获取列表
You can get first three row by你可以得到前三行
lines[:3]
If you want only the third row如果你只想要第三行
lines[2][0]
Also, I created an array similar to yours.另外,我创建了一个类似于你的数组。
x = np.array([[[1,2,3,4]],
[[5,6,7,8]],
[[5,6,7,8]],
[[5,6,7,8]],
[[5,6,7,8]]])
and和
x.shape => (5, 1, 4)
You have something wrong with the shape.你的形状有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.