0

I want to implement an operation on two matrices that is similar to matrix multiplication in that it each element of the resulting matrix is a function of the ith row of the first matrix and the jth column of the second matrix. I would like to be able to do this using numpy and/or pandas using vectorized computations.

In other words: How do I implemenent $A \bigotimes B = C$ where $C_{ij} = sum_k f(a_{ik}, b_{kj})$ in numpy and/or pandas?

Mig B
  • 637
  • 1
  • 11
  • 19
migs
  • 164
  • 10
  • 1
    show a sample of your input and output data [mcve] – Umar.H Dec 31 '19 at 23:26
  • 1
    Do you have a specific function in mind, or is this supposed to be a 'plug-your-function-in' case? To get speed that's anything like `dot`, you'll need to use compiled code, such as with `numba` or `cython`. – hpaulj Jan 01 '20 at 01:33
  • This https://stackoverflow.com/a/59256512/4045774 is an example for np.dot(A,B.T). Because of the memory alignment it may make sense to use this function and create a real transpose of B beforehand (np.copy(B.T)) – max9111 Jan 02 '20 at 14:44

0 Answers0