I have NumPy N-dimensional bool array b
.
It was converted to indices of True
values by i = np.nonzero(b)
.
What is the shortest one-liner to convert i
back to b
.
Of cause it can be done multi-line as:
b = np.zeros(b_shape, dtype = np.bool_)
b[i] = True
Obviously one-liner can be achieved by ;
-concatenation of lines, or some other tuple/lambda magic, or by defining a separate function.
But what I really want is to find some built-in NumPy function like b = np.indices_to_bools(i, shape = b_shape)
or to figure out some beautiful superposition of several built-in functions. So that solution can be embedded as a part of a bigger complex expression.
Also I want solution to be as efficient (CPU/RAM-wise) or almost as efficient as those two lines of code above. Not just any inefficient one-liner.