![](/img/trans.png)
[英]NumPy array IndexError: index 99 is out of bounds for axis 0 with size 1
[英]numpy array traversal Error: IndexError: index 1 is out of bounds for axis 0 with size 1
形状为(5,1)且具有以下元素的numpy:
[[1]
[2]
[3]
[4]
[5]]
您如何遍历并打印每个元素? 如下:
1
2
3
4
5
尝试
for row in range(N):
for col in range(D):
print(input_array[row][col])
错误
Error: IndexError: index 1 is out of bounds for axis 0 with size 1
您的N, D
值一定是错误的。 要么做
N, D = input_array.shape
并继续您的代码,或直接
for row in input_array:
for token in row:
print(token)
根据该错误, N
值是错误的。 应该是[0]
。
使用numpy.ndarray.shape函数进行计算应返回正确的行和列值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.