w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to efficiently use a index array as a mask to turn a numpy array into a boolean array?

You just need to add another dimension on to I, such that you can broadcast r properly:

result = r > I.reshape(I.shape[0],I.shape[1],1)

e.g.

In [41]: r>I.reshape(2,5,1)
Out[41]: 
array([[[False, False,  True],
        [False,  True,  True],
        [False, False, False],
        [False, False,  True],
        [False,  True,  True]],

       [[False,  True,  True],
        [False, False, False],
        [False, False,  True],
        [False,  True,  True],
        [False, False, False]]], dtype=bool)




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.