The mat()
function in Python is used to interpret an input array as a matrix.
numpy.mat(data, dtype=None)
The mat()
function takes the following parameters:
data
: This represents the input data or the array_like
object.dtype
: This represents the data type of the output matrix.The mat()
function returns data interpreted as a matrix.
import numpy as np# creating an arraymyarray = np.array([1, 2, 3, 4, 5, 6])# implementing the mat() fucntionmymatrix = np.mat(myarray, dtype = float)print(mymatrix)print(type(mymatrix))
numpy
module.array()
function. The result is assigned to a variable myarray
.mat()
function on the variable myarray
and use a float
data type for the output matrix. The result is assigned to a new variable mymatrix
.mymatrix
.type()
function, we obtain and print the object type of the variable mymatrix
we just created.Note: From the output
<class 'numpy.matrix'>
, we can see that the object is interpreted as a matrix.