NumPy Empty Function

PythonPythonBeginner
Practice Now

Introduction

In this lab, we will learn about the numpy.matlib.empty() function of the NumPy library. This function is used to return a new matrix with uninitialized entries. It is mainly used to configure matrices instead of ndarray objects.

VM Tips

After the VM startup is done, click the top left corner to switch to the Notebook tab to access Jupyter Notebook for practice.

Sometimes, you may need to wait a few seconds for Jupyter Notebook to finish loading. The validation of operations cannot be automated because of limitations in Jupyter Notebook.

If you face issues during learning, feel free to ask Labby. Provide feedback after the session, and we will promptly resolve the problem for you.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("`Python`")) -.-> python/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"]) python(("`Python`")) -.-> python/DataScienceandMachineLearningGroup(["`Data Science and Machine Learning`"]) python/BasicConceptsGroup -.-> python/variables_data_types("`Variables and Data Types`") python/BasicConceptsGroup -.-> python/numeric_types("`Numeric Types`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/ModulesandPackagesGroup -.-> python/importing_modules("`Importing Modules`") python/DataScienceandMachineLearningGroup -.-> python/numerical_computing("`Numerical Computing`") subgraph Lab Skills python/variables_data_types -.-> lab-86431{{"`NumPy Empty Function`"}} python/numeric_types -.-> lab-86431{{"`NumPy Empty Function`"}} python/tuples -.-> lab-86431{{"`NumPy Empty Function`"}} python/importing_modules -.-> lab-86431{{"`NumPy Empty Function`"}} python/numerical_computing -.-> lab-86431{{"`NumPy Empty Function`"}} end

Import NumPy and NumPy Matlib Libraries

Firstly, we will import the NumPy and NumPy Matlib libraries using the import keyword.

import numpy as np
import numpy.matlib

Use empty() function

The numpy.matlib.empty() function is used with following parameters,

  • shape for defining the size of the matrix
  • dtype(optional) for data type of the matrix
  • order(optional) for insertion order of matrix
np.matlib.empty((4,4))

Above code will generate the output as follows:

array([[ 0.00000000e+000,  0.00000000e+000,  0.00000000e+000, 0.00000000e+000],
       [ 0.00000000e+000,  0.00000000e+000,  0.00000000e+000, 0.00000000e+000],
       [ 8.61381863e+043, -1.94898979e-046,  9.88131292e-324, 0.00000000e+000],
       [ 1.13635099e-322,  0.00000000e+000,  0.00000000e+000, 0.00000000e+000]])

Additional Parameters for Data Type and Order

We can also use additional parameters while implementing the empty() function. dtype parameter for data type of the matrix and order parameter for its insertion order.

np.matlib.empty((2,3), int)

Above code will generate the output as follows:

array([[-1192611712,         306,           0],
       [           0,      131074,           0]])
np.matlib.empty((4), int, 'C')

Above code will generate the output as follows:

array([         0,          0,      65793,          1])

Summary

In this lab, we have learned about the numpy.matlib.empty() function used to return a new matrix having uninitialized entries. We also covered the syntax, parameters, and value returned by this function along with some code examples.

Summary

Congratulations! You have completed the NumPy Empty Function lab. You can practice more labs in LabEx to improve your skills.

Other Python Tutorials you may like