1

Given a 1d np.ndarray containing a list of indexes that is True: [1, 2, 4], and length of the target np.ndarray: 6

How can we quickly construct the actual np.ndarray which should be [False, True, True, False, True, False]

1 Answer 1

2
idx = [1,2,3]
s = 6
a = np.zeros(s,dtype=bool)
a[idx] = True

output:

[False  True  True  True False False]
Sign up to request clarification or add additional context in comments.

5 Comments

Dude you are incredible! And so is numpy!
Yes! I will accept your answer as soon as Stackoverflow allows me, you answered too quick!
Oh, did not know there is a time limit. Thank you.
stackoverflow.com/questions/62866197/… Do you think you can answer this one as well?
@HuadongFeng Please check my answer on that and see if it is what you are looking for. Thank you.

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.