Created
September 5, 2019 12:56
-
-
Save calbal91/151c1843aac989e3aa575bcf486bef4b to your computer and use it in GitHub Desktop.
Subtract Array Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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