1

Assuming we have two matrices A and B with dim of P * N and N * Q respectively, what is the more efficient way to get values from multiplication of those two matrices only at specific index? For example, vector of row index at {p1,p3,p6,p1,...} in matrix A multiplied by vector of column index at {q2,q5,q2,q3...} in matrix B, and returns scalar values.

There'a another dataframe storing the mapping of those row indexes and column indexes, for example,

row,column
p1,q2
p3,q5
p6,q2
p1,q3
...

like mentioned before.

jing wang
  • 21
  • 3

1 Answers1

0

Firstly, I would filter the desired rows and columns out of the matrix (2-D-array). Afterwards you can perform matrix multiplication with the reduced matrices, assigning the resulting vector to scalar variables if you like.

Regarding matrix multiplication, take a look at numpy.matmul.

Getting rows and columns from a matrix can be performed in many ways. This thread already provides some answers to your problem using numpy._ix or broadcasting.

I. Amon
  • 174
  • 11