0
0
NumPydata~5 mins

np.full() for custom-filled arrays in NumPy - Cheat Sheet & Quick Revision

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

np.full() creates a new array of a given shape and fills it with a specified value.

Click to reveal answer
beginner
How do you specify the shape of the array in np.full()?

You provide the shape as the first argument, either as an integer for 1D or a tuple for multi-dimensional arrays.

Click to reveal answer
beginner
What is the role of the fill_value parameter in np.full()?

fill_value is the value used to fill every element of the new array.

Click to reveal answer
intermediate
Can np.full() create arrays of different data types? How?

Yes, by using the optional dtype parameter, you can specify the data type of the array elements.

Click to reveal answer
beginner
Why might you use np.full() instead of np.zeros() or np.ones()?

Use np.full() when you want an array filled with a custom value other than 0 or 1.

Click to reveal answer
What is the correct way to create a 3x3 array filled with the number 7 using np.full()?
Anp.full(3, 3, 7)
Bnp.full(3, 7)
Cnp.full(7, (3, 3))
Dnp.full((3, 3), 7)
Which parameter in np.full() controls the data type of the array elements?
Ashape
Bdtype
Cfill_value
Dorder
What will np.full(5, 0) create?
AA 5x5 array filled with zeros
BA scalar zero
CA 1D array of length 5 filled with zeros
DAn error
If you want a 2x2 array filled with the string 'hi', which code is correct?
Anp.full((2, 2), 'hi')
Bnp.full((2, 2), hi)
Cnp.full(2, 'hi')
Dnp.full('hi', (2, 2))
What happens if you do not specify dtype in np.full()?
AIt infers the data type from the fill value
BIt defaults to float64
CIt raises an error
DIt defaults to int32
Explain how to create a 4x4 NumPy array filled with the number 9 using np.full(). Include how to specify the shape and fill value.
Think about the first argument as shape and second as the value to fill.
You got /4 concepts.
    Describe the difference between np.full() and np.zeros(). When would you use each?
    Consider what value you want in the array.
    You got /4 concepts.