numpy.zeros() in PythonThe 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. SyntaxParametersshape: 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) ReturnThis function returns a ndarray. The output array is the array with specified shape, dtype, order, and contains zeros. Example 1: numpy.zeros() without dtype and orderOutput: array([0., 0., 0., 0., 0., 0.]) In the above code
In the output, an array with floating-point integers(zeros) has been shown. Example 2: numpy.zeros() without orderOutput: array([0, 0, 0, 0, 0, 0]) Example 3: numpy.zeros() with shapeOutput: array([[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.]]) In the above code
In the output, an array of given shape has been shown. Example 4: numpy.zeros() with the shapeOutput: array([[0., 0.], [0., 0.], [0., 0.]]) Example 5: numpy.zeros() with custom dtypeOutput: array([(0, 0), (0, 0), (0, 0)], dtype=[('x', '<i4'), ('y', '<i4')]) In the above code
In the output, an array contains zeros with custom data-type has been shown. Next Topicnumpy.log() |