python - efficient way to compute numpy.ndarray internal multiplication -


I have two matrix A and B with the same size:
  a = Np Ndarray (size = (3, 2), dtype = int) b = np.ndarray (size = (3, 2), dtype = int)   

and I should multiply internally They like:

  1 2 a = 4 5 7 8 9 8b = 6 5 3 2   

And the result should be 1x2 ndarray: < / P>

  [1x 9 + 4x6 + 7x3 2x8 + 5x5 + 8x2]   

It is similar that we are computing the scaler dot product of two columns matrix .

What I am doing now:

  np.diag (np.dot (np.transpose (a), b))   

But it's not efficient and it's calculating many other things I do not need.

My metrics are much more than these, so it is important to find a more efficient solution.

You can do simple multiplication first and then zodiac on the axis = 0:

  & gt; & Gt; & Gt; A = np.array ([[1, 2], [4, 5], [7, 8]]) gt; & Gt; & Gt; B = np.array ([[9, 8], [6, 5], [3, 2]]) gt; & Gt; & Gt; (A * b) .sum (axis = 0) array ([54, 57])    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -