#🔒 HOW does 3D NumPy array actually do matrix multiplication

13 messages · Page 1 of 1 (latest)

little bramble
#

I'm trying to understand, how does 3D NumPy arrat actually do matrix multiplication under with hood (np.matmul (arr1, arr2))

import numpy as np
arr1 = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
arr2 = np.array([[[4, 5, 6], [3, 2, 1]], [[7, 8, 9], [12, 10, 11]]])
print(np.matmul(arr1, arr2))
#this throws an error, 
#by going through the error, i find out that, arr1's shape(x,p,n) and arr2's shape #should be(x,n,p)
#that is last dimension of arr1=2nd last dimension of arr2
#but why is that, and what's the actual mathematical operation..

#help me to understand
lucid edgeBOT
#

@little bramble

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cosmic wagon
#

My general understanding has always been that the two arrays should be the same shape.

cosmic wagon
cosmic wagon
#

The shapes have to be compatible.

#

But numpy being numpy, the shapes don't necessarily have to be equal.

little bramble
little bramble
little bramble
lucid edgeBOT
#
Python help channel closed using Discord native close action

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.