Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. def subtract_array(full_array, sub_array):
  2.  
  3. '''
  4. Take one numpy array (full array),
  5. and "remove" another (sub_array) from it.
  6.  
  7. e.g. subtract_array([1,1,3,5,5,6,7], [1,5,6])
  8. returns [1,3,5,7]
  9.  
  10. sub_array must be a sub-set of the full_array
  11.  
  12. '''
  13.  
  14. #For each element, i, in the subarray...
  15. for i in sub_array:
  16.  
  17. #Delete the first instance of i from the full array (but leave other instances)
  18. full_array = np.delete(full_array, np.where(full_array == i)[0][0])
  19.  
  20. return full_array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement