Bird
0
0

What does the function np.arange(5) do in NumPy?

easy📝 Conceptual Q1 of 15
NumPy - Creating Arrays
What does the function np.arange(5) do in NumPy?
ACreates an array with values from 1 to 5
BCreates an array with values from 0 to 4
CCreates an array with values from 0 to 5
DCreates an array with values from 1 to 4
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.arange with one argument

    When np.arange is called with one argument n, it creates values starting from 0 up to but not including n.
  2. Step 2: Apply np.arange(5)

    So np.arange(5) creates an array with values 0, 1, 2, 3, 4.
  3. Final Answer:

    Creates an array with values from 0 to 4 -> Option B
  4. Quick Check:

    np.arange(5) = [0 1 2 3 4] [OK]
Quick Trick: np.arange(n) starts at 0 and stops before n [OK]
Common Mistakes:
  • Assuming it starts at 1
  • Including the stop value
  • Confusing with range() function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes