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:
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join