What is the numpy.ma.empty() function in Python?

Overview

In Python, the ma.empty() function is used to create a new array of a given shape and type without the entries being initialized and random elements.

Syntax

ma.empty(shape, dtype=float, order='C', *, like=None)

Parameters

This function takes the following parameter values:

  • shape: This is the shape of the resulting array.
  • dtype: This is the data type of the resulting array—for example, numpy.int8. The default value is numpy.float64. This is optional.
  • like: This is a reference to an object that allows us to create new arrays which are not NumPy arrays.
import numpy as np
# creating a shape for the array
myshape = (2,3)
# implementing the ma.empty() function
newarray = np.empty(myshape, dtype=float, order="F" )
# printing the array
print(newarray)

Explanation

  • Line 1: We import the numpy module.
  • Line 4: We create a shape for the resulting array.
  • Line 7: We implement the ma.empty() function. The result is assigned to a variable newarray.
  • Line 10: We print the variable newarray.

Free Resources