I have a 2D numpy array of zeros that looks like this:
stock2concept_matrix = np.zeros((3, 4))
I have a row mask, which is a list of indices from 0 to 2:
row = [0, 1, 2]
A column mask looks like this:
column = [[0, 2], [1], [0, 2, 3]]
I expect that
stock2concept_matrix[row, column] = 1
will change stock2concept_matrix to:
[[1, 0, 1, 0],
[0, 1, 0, 0],
[1, 0, 1, 1]]
However, an error occurred:
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
I don't want to use a for loop since it's inefficient, how can I achieve my goal?