1. Home
  2. Data Science
  3. NumPy
  4. If x has shape (5,), what is the shape of x[:, np.newaxis]?

Added 2 Nov 2026

If x has shape (5,), what is the shape of x[:, np.newaxis]?

  1. (1, 5)
  2. (5, 1) Correct answer
  3. (5, 5)
  4. (5,)

Correct answer

B. (5, 1)

17 views

MCQSEXAM

Explanation

np.newaxis inserts a dimension of length 1, turning x into a column vector. This is often done to enable broadcasting against a row vector.

Reference

Asked in: Data Science Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More NumPy MCQs

Practise all NumPy MCQs

Similar MCQs