Analyze Data/Python Libraries
numpy-zeros, zeros_like
Naranjito
2024. 3. 22. 13:31
- zeros
Returns a new array of given shape and type, filled with zeros.
np.zeros((5,), dtype=int)
>>>
array([0, 0, 0, 0, 0])
s = (2,2)
np.zeros(s)
>>>
array([[ 0., 0.],
[ 0., 0.]])
- zeros_like
Return an array of zeros with the same shape and type as a given array.
x = np.arange(6)
x = x.reshape((2, 3))
x
>>>
array([[0, 1, 2],
[3, 4, 5]])
np.zeros_like(x)
array([[0, 0, 0],
[0, 0, 0]])
y = np.arange(3, dtype=float)
y
>>>
array([0., 1., 2.])
np.zeros_like(y)
>>>
array([0., 0., 0.])