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 the array_like object 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 type
my_array = np.zeros(5, dtype = int)
print(my_array)

Explanation

  • Line 1: We import the numpy module.
  • Line 4: We implement the ma.zeros() function to create an array with its 5 elements set to 0. We assigned the result to a variable my_array.
  • Line 6: We print the new array my_array.

Free Resources