我有兩個長度相同的一維陣列(it和l),我想洗掉for <中的元素y,并洗掉相同位置的元素。我試過了:lllsxit
for x, y in zip(it, l):
if y < ls:
np.delete(l,y)
np.delete(it,x)
但它不起作用,并且有警告:
“DeprecationWarning:在洗掉中使用非整數陣列作為 obj 將在未來導致錯誤”np.delete(l,y)
“棄用警告:在洗掉中使用非整數陣列作為 obj 將導致未來 np.delete(it,x) 出錯”
uj5u.com熱心網友回復:
這里有一個例子。
您必須指出要洗掉的元素的索引:
import numpy as np
it = np.asarray(range(10))
l = np.asarray(range(10))
ls = 4
index = []
for i, y in enumerate(l):
if y < ls:
index.append(i)
l = np.delete(l, index)
it = np.delete(it, index)
結果 :
(array([4, 5, 6, 7, 8, 9]), array([4, 5, 6, 7, 8, 9]))
較短的版本:
index = np.argwhere(l < ls)
l = np.delete(l, index)
it = np.delete(it, index)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/519635.html
