我有一个数组“removable”,其中包含另一个数组“All”中的一些数字,该数组包含从 0 到 k 的所有数字。
我想删除列在 removable 中的 A 中的所有数字。
All = np.arange(k)
removable = np.ndarray([1, 3, 4 , 7, 9, ..., 200])
for i in removable:
if i in All:
All.remove(i)
ndarray 没有 remove 属性,但我确信 numpy 中有一个简单的方法可以解决这个问题,但我在文档中找不到它。
最佳答案
您可以使用函数 setdiff1d来自 NumPy:
>>> a = np.array([1, 2, 3, 2, 4, 1])
>>> b = np.array([3, 4, 5, 6])
>>> np.setdiff1d(a, b)
array([1, 2])
关于python - 从一个数组中删除另一个数组中的所有数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54536979/