0
0
Data Analysis Pythondata~5 mins

Array creation (array, arange, linspace) in Data Analysis Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the numpy.array() function do?
It creates a new array from a list or sequence of numbers. This array can be used for fast math and data operations.
Click to reveal answer
beginner
How does numpy.arange() differ from Python's built-in range()?
numpy.arange() can create arrays with decimal steps, not just whole numbers like range(). It returns a NumPy array instead of a list.
Click to reveal answer
beginner
What is the purpose of numpy.linspace()?
It creates an array of evenly spaced numbers between a start and stop value, including the stop value. You specify how many numbers you want.
Click to reveal answer
intermediate
Example: What does np.arange(1, 5, 0.5) produce?
It creates an array starting at 1, increasing by 0.5, up to but not including 5: [1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5]
Click to reveal answer
intermediate
Why might you choose linspace() over arange()?
Because linspace() lets you specify the exact number of points you want between start and stop, which is helpful for precise spacing. arange() uses step size, which can cause rounding issues.
Click to reveal answer
Which function creates an array with a specific number of evenly spaced points between two values?
Anumpy.array()
Bnumpy.linspace()
Cnumpy.arange()
DPython range()
What will np.arange(0, 3, 1) output?
A[0, 1, 2]
B[1, 2, 3]
C[0, 1, 2, 3]
D[0, 1, 2, 3, 4]
Which function converts a Python list into a NumPy array?
Anumpy.array()
Bnumpy.arange()
Cnumpy.tolist()
Dnumpy.linspace()
If you want 5 numbers evenly spaced from 0 to 1, which function and parameters would you use?
Anp.array([0, 0.2, 0.4, 0.6, 0.8])
Bnp.arange(0, 1, 0.2)
Cnp.linspace(0, 1, 5)
Dnp.arange(0, 1, 0.25)
What type of object do numpy.array(), arange(), and linspace() return?
APython list
BDictionary
CTuple
DNumPy array
Explain how to create a NumPy array from a Python list and why you might want to do this.
Think about turning simple lists into powerful arrays for calculations.
You got /4 concepts.
    Describe the difference between arange() and linspace() and when to use each.
    Focus on how you control the spacing and number of points.
    You got /5 concepts.