Issue
I have an array "removable" containing a few numbers from another array "All" containing all numbers from 0 to k.
I want to remove all numbers in A which are listed in removable.
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 has no remove attribute, but I'm sure there is an easy method in numpy to solve this problem, but I can't find it in the documentation.
Solution
You could use the function setdiff1d from NumPy:
>>> a = np.array([1, 2, 3, 2, 4, 1])
>>> b = np.array([3, 4, 5, 6])
>>> np.setdiff1d(a, b)
array([1, 2])
Answered By - f.wue
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.