How can you turn an index array into a mask array in Numpy?

前端 未结 4 1078
孤街浪徒
孤街浪徒 2020-12-14 17:04

Is it possible to convert an array of indices to an array of ones and zeros, given the range? i.e. [2,3] -> [0, 0, 1, 1, 0], in range of 5

I\'m trying to automate so

4条回答
  •  情深已故
    2020-12-14 17:36

    As requested, here it is in an answer. The code:

    [x in index_array for x in range(500)]
    

    will give you a mask like you asked for, but it will use Bools instead of 0's and 1's.

提交回复
热议问题