我正在使用python-3.x,並且搜索了有關以下錯誤的信息,但找不到正確的解決方案。刪除基於花葯數組中最小值的數組中的一行
的錯誤是:
IndexError: index 9 is out of bounds for axis 0 with size 9'
那麼,我做的是創造隨機二進制數組「二進制」也是一個隨機數陣列的「價值」,我想基於二進制數組中刪除最低的兩排在「值」數組中的最小兩個值的(索引)上。
據我所知我正在訪問數組的邊界之外,但是解決這個錯誤的正確方法是什麼?
在我的代碼那麼,問題出在哪裏以及如何解決它的任何幫助,將不勝感激
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)
在這段代碼中,我用np.argmin,因爲我不想讓使用排序。