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)
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:
Python - NumPy Code Editor:
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
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics