0
0
NumPydata~5 mins

np.zeros() for zero-filled arrays in NumPy - Cheat Sheet & Quick Revision

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

np.zeros() creates a new array filled with zeros. You specify the shape (size) of the array, and it returns an array of that shape with all elements set to zero.

Click to reveal answer
beginner
How do you create a 3x3 zero-filled array using np.zeros()?

Use np.zeros((3, 3)). The argument is a tuple representing the shape: 3 rows and 3 columns.

Click to reveal answer
beginner
What data type does np.zeros() use by default?

By default, np.zeros() creates an array of floats (floating-point numbers).

Click to reveal answer
intermediate
How can you create a zero-filled array of integers using np.zeros()?

Use the dtype parameter: np.zeros((3, 3), dtype=int) creates a 3x3 array of zeros as integers.

Click to reveal answer
beginner
Why might you use np.zeros() in data science?

It helps to initialize arrays before filling them with data or results. For example, creating empty containers for calculations or placeholders for missing data.

Click to reveal answer
What is the output of np.zeros(5)?
A[0 0 0 0 0]
B[1 1 1 1 1]
C[5 5 5 5 5]
DAn error
How do you specify the shape of a 2D zero array with 4 rows and 2 columns?
Anp.zeros((4, 2))
Bnp.zeros([4, 2])
Cnp.zeros(4, 2)
Dnp.zeros{4, 2}
What is the default data type of elements in np.zeros()?
Aint
Bstr
Cfloat
Dbool
Which parameter changes the data type of zeros in np.zeros()?
Atype
Bshape
Csize
Ddtype
Why use np.zeros() instead of a Python list of zeros?
ANumPy arrays are slower but prettier
BNumPy arrays are faster and use less memory
CPython lists cannot hold zeros
DPython lists do not support zeros
Explain how to create a zero-filled 2D array with 5 rows and 4 columns using np.zeros(). Include how to specify the data type as integers.
Remember the shape is a tuple and use dtype=int.
You got /4 concepts.
    Describe three common reasons why data scientists use np.zeros() when working with data.
    Think about starting points for data or results.
    You got /3 concepts.