Skip to content

Instantly share code, notes, and snippets.

@calbal91
Created September 5, 2019 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calbal91/151c1843aac989e3aa575bcf486bef4b to your computer and use it in GitHub Desktop.
Save calbal91/151c1843aac989e3aa575bcf486bef4b to your computer and use it in GitHub Desktop.
Subtract Array Function
def subtract_array(full_array, sub_array):
'''
Take one numpy array (full array),
and "remove" another (sub_array) from it.
e.g. subtract_array([1,1,3,5,5,6,7], [1,5,6])
returns [1,3,5,7]
sub_array must be a sub-set of the full_array
'''
#For each element, i, in the subarray...
for i in sub_array:
#Delete the first instance of i from the full array (but leave other instances)
full_array = np.delete(full_array, np.where(full_array == i)[0][0])
return full_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment