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()?✗ Incorrect
The shape must be a tuple (3, 3) and the fill value is 7.
Which parameter in
np.full() controls the data type of the array elements?✗ Incorrect
dtype sets the data type of the array elements.
What will
np.full(5, 0) create?✗ Incorrect
Shape is 5, so a 1D array of length 5 filled with 0.
If you want a 2x2 array filled with the string 'hi', which code is correct?
✗ Incorrect
The shape is (2, 2) and the fill value is the string 'hi'.
What happens if you do not specify
dtype in np.full()?✗ Incorrect
NumPy guesses the data type based on the fill value.
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.