Given an array with size MxN and an array with size Mx1, I want to compute a boolean array with MxN.
import numpy as np
M = 2
N = 3
a = np.random.rand(M, N) # The values doesn't matter
b = np.random.choice(a=N, size=(M, 1), replace=True)
# b =
# array([[2],
# [1]])
# I found this way to compute the boolean array but I wonder if there's a fancier, elegant way
index_array = np.array([np.array(range(N)), ]*M)
# Create an index array
# index_array =
# array([[0, 1, 2],
# [0, 1, 2]])
#
boolean_array = index_array == b
# boolean_array =
# array([[False, False, True],
# [False, True, False]])
#
So i wonder if theres's a fancier, pythonic way of doing this