What is the numpy.ma.zeros() function in NumPy?
Overview
The ma.zeros() function is used to return a new array of a given shape and type filled with zeros.
Syntax
The function has the following syntax:
ma.zeros(shape, dtype=float, order='C', *, like=None)
Syntax for the ma.zeros() function in NumPy
Parameters
The ma.zeros() function takes the following parameter values:
shape: This represents the desired or the new array.dtype: This represents the desired data type of the array and is optional.like: This represents thearray_likeobject or the prototype.
Return value
The ma.zeros() function returns an array with the given shape and data type filled with zeros.
Code
import numpy as np# creating a prototype or array_like object with an integer data typemy_array = np.zeros(5, dtype = int)print(my_array)
Explanation
- Line 1: We import the
numpymodule. - Line 4: We implement the
ma.zeros()function to create an array with its5elements set to0. We assigned the result to a variablemy_array. - Line 6: We print the new array
my_array.