I was trying out indexing using boolean arrays
def boolean_array_indexing_each_dim1():
a = np.array(
[
['a','b','c','d'],
['e','f','g','h'],
['i','j','k','l'],
['m','n','o','p']
]
)
print('a=\n',a.shape,'\n',a)
b1 = np.array([True,True,True,False]) #gives error
#b1 = np.array([True,False,True,False]) #works
print('b1=\n',b1.shape,'\n',b1)
b2 = np.array([True,False,True,False])
print('b2=\n',b2.shape,'\n',b2)
selected = a[b1,b2]
print('selected=\n',selected.shape,'\n',selected)
the array b1 = np.array([True,True,True,False]) causes a 'ValueError shape mismatch: objects cannot be broadcast to a single shape'
The array b1 = np.array([True,False,True,False]) however works and produces a result ' ['a' 'k']'
why does this error happen? can someone please tell ?