Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
python
communitycreator

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

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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)
Implementing the ma.empty() function

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.

RELATED TAGS

function
python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring