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 isnumpy.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 arraymyshape = (2,3)# implementing the ma.empty() functionnewarray = np.empty(myshape, dtype=float, order="F" )# printing the arrayprint(newarray)
Explanation
- Line 1: We import the
numpymodule. - Line 4: We create a
shapefor the resulting array. - Line 7: We implement the
ma.empty()function. The result is assigned to a variablenewarray. - Line 10: We print the variable
newarray.