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.
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,
shapefor defining the size of the matrixdtype(optional) for data type of the matrixorder(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.