Bird
0
0

Which of the following is the correct syntax to create a 1D array of five ones using NumPy?

easy📝 Syntax Q3 of 15
NumPy - Creating Arrays
Which of the following is the correct syntax to create a 1D array of five ones using NumPy?
Anp.ones(5)
Bnp.ones([5,])
Cnp.ones((5,))
DAll of the above
Step-by-Step Solution
Solution:
  1. Step 1: Understand 1D array shape

    A 1D array shape can be an integer, a list with one element, or a tuple with one element.
  2. Step 2: Check each syntax

    np.ones(5) uses an integer 5, valid for 1D array. np.ones([5,]) uses a list with one element [5,], valid. np.ones((5,)) uses a tuple (5,), also valid.
  3. Final Answer:

    All of the above -> Option D
  4. Quick Check:

    1D array shape can be int, list, or tuple [OK]
Quick Trick: 1D shape can be int, list, or tuple with one element [OK]
Common Mistakes:
  • Using tuple without comma for single element
  • Confusing 1D and 2D shapes
  • Syntax errors with missing parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes