w3resource

NumPy: numpy.mat() function

numpy.mat() function

The numpy.mat function is used to interpret the input as a matrix, and if necessary, convert it to a matrix. It returns a matrix from a string, nested sequence, or array-like object.

Syntax:

numpy.mat(data, dtype=None)
NumPy array: mat() function

Parameters:

Name Discription Required / Optional
data input data. Required
dtype Data-type of the output matrix. optional

Return value:

mat : matrix - data interpreted as a matrix.

Example: NumPy.mat() method

import numpy as np
# creating an array
arr = np.array([1, 2, 3, 4, 5, 6])
# implementing the mat() fucntion 
matrix = np.mat(arr, dtype = float)
print(matrix)
print(type(matrix))

Output:

[[1. 2. 3. 4. 5. 6.]]

Pictorial Presentation:

NumPy array: mat() function

Python - NumPy Code Editor:

Previous: vander()
Next: bmat()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/numpy/array-creation/mat.php