0

I have an array and a sub-array, like following:

import numpy as np    
total_array = np.arange(10)
sub_array = np.array([0, 1, 2, 3])

I was wondering how to get the rest_array = total_array - sub_array = np.array([4, 5, 6, 7, 8, 9])?

Any simple ideas? Thanks in advance.

1 Answer 1

1

You can simply use np.setdiff1d to get the result you want

import numpy as np    
total_array = np.arange(10)
sub_array = np.array([0, 1, 2, 3])

rest_array = np.setdiff1d(total_array, sub_array)
rest_array

array([4, 5, 6, 7, 8, 9])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.