NumPy Operations
The NumPy calls that implement each math operation, with shapes.
Creating & inspecting arrays
Assumes `import numpy as np`.
| Task | NumPy call | Notes / shape |
|---|---|---|
From a list |
| Shape |
Zeros / ones |
| Give the shape as a tuple; here |
Range |
|
|
Random normal |
| Standard-normal entries, shape |
Inspect shape |
| Tuple of dimension sizes. |
Number of dims |
| Length of |
Reshaping & reductions
| Task | NumPy call | Notes / shape |
|---|---|---|
Reshape |
| Total elements must match; use |
Add an axis |
|
|
Sum all |
| Returns a scalar. |
Sum over an axis |
| Collapses that axis; |
Mean over an axis |
|
|
Argmax |
| Index of max along the axis; drops that axis. |
Linear algebra & broadcasting
| Task | NumPy call | Notes / shape |
|---|---|---|
Matrix multiply |
|
|
Transpose |
|
|
Vector / matrix norm |
| L2 by default; pass |
Solve |
| Prefer over |
Broadcasting |
|
|
Element-wise op |
| Equal shapes (or broadcastable); element-wise product. |