The numpy.zeros() function is one of the most significant functions which is used in machine learning programs widely. This function is used to generate an array containing zeros.
The numpy.zeros() function provide a new array of given shape and type, which is filled with zeros.
numpy.zeros(shape, dtype=float, order='C'
shape: int or tuple of ints
This parameter is used to define the dimensions of the array. This parameter is used for the shape in which we want to create an array, such as (3,2) or 2.
dtype: data-type(optional)
This parameter is used to define the desired data-type for the array. By default, the data-type is numpy.float64. This parameter is not essential for defining.
order: {'C','F'}(optional)
This parameter is used to define the order in which we want to store data in memory either row-major(C-style) or column-major(Fortran-style)
This function returns a ndarray. The output array is the array with specified shape, dtype, order, and contains zeros.
import numpy as np a=np.zeros(6) a
Output:
In the above code
In the output, an array with floating-point integers(zeros) has been shown.
import numpy as np a=np.zeros((6,), dtype=int) a
Output:
import numpy as np a=np.zeros((6,2)) a
Output:
In the above code
In the output, an array of given shape has been shown.
Import numpy as np s1=(3,2) a=np.zeros(s1) a
Output:
Import numpy as np a=np.zeros((3,), dtype=[('x', 'i4'), ('y', 'i4')]) a
Output:
In the above code
In the output, an array contains zeros with custom data-type has been shown.