NumPy contains a matrix library, i.e. numpy.matlib which is used to configure matrices instead of ndarray objects.
This function is used to return a new matrix with the uninitialized entries. The syntax to use this function is given below.
numpy.matlib.empty(shape, dtype, order)
It accepts the following parameter.
Consider the following example.
import numpy as np import numpy.matlib print(numpy.matlib.empty((3,3)))
Output:
This function is used to create the matrix where the entries are initialized to zero.
Consider the following example.
import numpy as np import numpy.matlib print(numpy.matlib.zeros((4,3)))
Output:
This function returns a matrix with all the elements initialized to 1.
Consider the following example.
import numpy as np import numpy.matlib print(numpy.matlib.ones((2,2)))
Output:
This function returns a matrix with the diagonal elements initialized to 1 and zero elsewhere. The syntax to use this function is given below.
numpy.matlib.eye(n, m, k, dtype)
It accepts the following parameters.
Consider the following example.
import numpy as np import numpy.matlib print(numpy.matlib.eye(n = 3, M = 3, k = 0, dtype = int))
Output:
This function is used to return an identity matrix of the given size. An identity matrix is the one with diagonal elements initializes to 1 and all other elements to zero.
Consider the following example.
import numpy as np import numpy.matlib print(numpy.matlib.identity(5, dtype = int))
Output:
This function is used to generate a matrix where all the entries are initialized with random values.
Consider the following example.
import numpy as np import numpy.matlib print(numpy.matlib.rand(3,3))
Output: