【发布时间】:2018-01-11 02:52:53
【问题描述】:
我正在使用python-3.x,我搜索了以下错误,但找不到正确的解决方案。错误发生在以下代码中。
我有一个随机 numpy 二进制数组和一个随机数数组,因此代码将根据另一个数组的值删除一个二进制行,正如您从代码中看到的那样。
import random
import numpy as np
np.set_printoptions(threshold=np.nan)
for i in range (100):
binary= np.random.randint (2, size=(10, 4))
print("binary:" '\n',binary)
value = np.random.randint (200, size=(10, 1))
print("value:" '\n',value)
for i in range (2):
# the loseer how have the of the binarys who has the smaslets value
loser = np.argmin(value)
# print ("loser:",loser)
# print("loser:", loser,(value[loser]))
# print (binary[loser,])
# print("Loser=", "Index:", loser,"value:",(value[loser]), "binary:",(binary[loser,]))
print("Index:", loser)
print("value:",(value[loser]))
print("binary:",(binary[loser,]))
print("Loser=", "Index:", loser,"value:",(value[loser]), "binary:",(binary[loser,]))
binary = np.delete(binary, (loser), axis=0)
print("binary:" '\n',binary)
错误是:IndexError: index 9 is out of bounds for axis 0 with size 9'
那么在我的代码中,问题出在哪里以及如何解决它 任何帮助将不胜感激
【问题讨论】:
标签: arrays python-3.x indexing