Bird
0
0

You want to create an array starting at 10, decreasing by 2, stopping before 0. Which np.arange() call is correct?

hard📝 Application Q15 of 15
NumPy - Creating Arrays
You want to create an array starting at 10, decreasing by 2, stopping before 0. Which np.arange() call is correct?
Anp.arange(0, 10, -2)
Bnp.arange(10, 0, 2)
Cnp.arange(10, 0, -2)
Dnp.arange(0, 10, 2)
Step-by-Step Solution
Solution:
  1. Step 1: Identify start, stop, and step for decreasing sequence

    Start=10, stop=0 (excluded), step must be negative to decrease.
  2. Step 2: Check each option

    np.arange(10, 0, -2) uses step=-2 correctly. np.arange(10, 0, 2) has positive step, so no values. Options C and D start at 0, which is not desired.
  3. Final Answer:

    np.arange(10, 0, -2) -> Option C
  4. Quick Check:

    Decreasing sequence needs negative step [OK]
Quick Trick: Use negative step to count down in np.arange [OK]
Common Mistakes:
  • Using positive step for decreasing sequence
  • Swapping start and stop values
  • Starting at stop value instead of start

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes