0
0
NumPydata~5 mins

np.arange() for range arrays in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does np.arange() do in NumPy?

np.arange() creates an array with evenly spaced values within a specified range, similar to Python's built-in range() but returns a NumPy array.

Click to reveal answer
beginner
How do you create an array from 0 to 9 using np.arange()?

Use np.arange(10). It creates values starting at 0 up to but not including 10.

Click to reveal answer
beginner
What parameters does np.arange() accept?

np.arange(start, stop, step) where:

  • start: where to begin (default 0)
  • stop: where to stop (not included)
  • step: gap between values (default 1)
Click to reveal answer
intermediate
Can np.arange() create arrays with decimal steps?

Yes! For example, np.arange(0, 1, 0.2) creates [0. , 0.2, 0.4, 0.6, 0.8].

Click to reveal answer
intermediate
What happens if the step parameter is negative in np.arange()?

The array counts downwards. For example, np.arange(5, 0, -1) creates [5, 4, 3, 2, 1].

Click to reveal answer
What is the output of np.arange(3)?
A[0, 1, 2, 3]
B[1, 2, 3]
C[0, 1, 2]
D[3]
Which parameter in np.arange(start, stop, step) is required?
Astart
Bstop
Cstep
DNone, all are optional
What does np.arange(1, 5, 2) produce?
A[1, 3]
B[1, 2, 3, 4]
C[1, 3, 5]
D[2, 4]
Can np.arange() generate an empty array?
ANo, it always returns values
BOnly if step is negative
COnly if step is zero
DYes, if start >= stop
What is the difference between np.arange() and Python's range()?
A<code>np.arange()</code> returns a NumPy array, <code>range()</code> returns a range object
BNo difference
C<code>range()</code> supports decimal steps
D<code>np.arange()</code> only works with integers
Explain how to use np.arange() to create an array of numbers from 5 to 15 with a step of 3.
Remember the stop value is not included in the output.
You got /5 concepts.
    Describe how np.arange() handles decimal steps and why it might be useful.
    Think about creating sequences with fractions or floats.
    You got /4 concepts.