implementing np.dot on 2D arrays resulting in unexpected broadcasting behavior in NumPy 1.21
I've searched everywhere and can't find a clear answer. I'm following best practices but Hey everyone, I'm running into an issue that's driving me crazy... I'm reviewing some code and I'm working with an scenario with `np.dot` when trying to perform matrix multiplication on two 2D arrays. I have the following code snippet: ```python import numpy as np a = np.array([[1, 2], [3, 4]]) # Shape (2, 2) b = np.array([[5], [6], [7]]) # Shape (3, 1) result = np.dot(a, b) ``` When I run this, I get the behavior: ``` ValueError: shapes (2,2) and (3,1) not aligned: 2 (dim 1) != 3 (dim 0) ``` I expected `np.dot` to automatically handle the shapes if they are compatible via broadcasting, but it seems like that is not the case here. It's clear that the inner dimensions don't match, but I assumed broadcasting would allow the operation to work correctly. I've tried reshaping `b` using `b.reshape(1, 3)` but that leads to a different behavior: ``` ValueError: shapes (2,2) and (1,3) not aligned: 2 (dim 1) != 1 (dim 0) ``` I also experimented with `np.matmul`, which gives me a similar behavior. My intention is to combine these arrays in a way where I can leverage the rows of `a` with the values of `b`. Is there a specific way to align these dimensions properly for matrix multiplication using NumPy, or am I missing a key concept about how broadcasting works in this context? Any insights or alternative approaches would be greatly appreciated! This issue appeared after updating to Python LTS. Any ideas what could be causing this? I'm developing on Ubuntu 22.04 with Python. Is there a simpler solution I'm overlooking? What's the best practice here?