All courses › Intermediate Programming › Matrix operations
Matrix operations
A * B between two NumPy arrays is elementwise multiplication, while np.dot(A, B) or A @ B is true matrix multiplication. reshape changes an array's shape without changing the data, and -1 lets NumPy work out the last dimension itself.
matrix multiplication
elementwise multiplication (requires the same shape)
Symbols
| matrices (2D NumPy arrays) |
Example
np.arange(12).reshape(4, -1).shape gives (4, 3), since .
A * B and A @ B give very different results — use @ when you mean matrix multiplication.