How do I use np.newaxis in NumPy?

@Punamhans For me, np.newaxis is super helpful when I want to make two arrays compatible for broadcasting.

Like, say I have a column vector and I want to add it to a row vector:


python
Copy
Edit
a = np.array([1, 2, 3])[:, np.newaxis]  # shape (3, 1)
b = np.array([10, 20, 30])              # shape (3,)

Now I can broadcast a + b.T easily.

Without np.newaxis, I’d have to reshape manually, which feels less readable.