Mismatched shapes causing ValueError with np.dot and 3D arrays in NumPy 1.25
I'm working on a personal project and I've been working on this all day and Hey everyone, I'm running into an issue that's driving me crazy. I've looked through the documentation and I'm still confused about I'm working with a `ValueError` when trying to perform a dot product using `np.dot` on two 3D arrays in NumPy 1.25. The shapes of the arrays are (2, 4, 3) and (2, 3, 5), and I'm trying to multiply them together to get a result of shape (2, 4, 5). However, I receive the following behavior: ``` ValueError: shapes (2,4,3) and (2,3,5) not aligned: 3 (dim 2) != 3 (dim 1) ``` I expected NumPy to handle this operation by aligning the inner dimensions and producing a valid output. To troubleshoot, I attempted to reshape both arrays to 2D before running `np.dot`, but got the same behavior. Hereβs the code snippet I used: ```python import numpy as np A = np.random.rand(2, 4, 3) # Shape (2, 4, 3) B = np.random.rand(2, 3, 5) # Shape (2, 3, 5) # Attempting dot product result = np.dot(A, B) # This raises ValueError ``` I also tried using `np.matmul`, which also resulted in an behavior: ```python result = np.matmul(A, B) # Same scenario ``` Is there a specific way to handle 3D array multiplication without running into this scenario? Am I missing a crucial detail about the dimensionality or alignment rules? Any guidance would be greatly appreciated! Has anyone else encountered this? This is part of a larger service I'm building. The project is a microservice built with Python.