0 votes
in Python by
How can you initialize a 5*5 numpy array with only zeroes?

1 Answer

0 votes
by

Solution ->

We will be using the .zeros() meethod

Use np.zeros() and pass in the dimensions inside it. Since, we want a 5*5 matrix, we will pass (5,5) inside the .zeros() method.

This will be the output:

array([ 0.,  0.,  0.,  0.,  0.])
>>> np.zeros((5,), dtype=int)
array([0, 0, 0, 0, 0])
>>> np.zeros((2, 1))
array([[ 0.],
       [ 0.]])
>>> s = (2,2)
>>> np.zeros(s)
array([[ 0.,  0.],
       [ 0.,  0.]])

Related questions

+2 votes
asked Jul 3, 2021 in NumPy by sharadyadav1986
0 votes
asked Feb 11, 2021 in Python by SakshiSharma
...