Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

NumPy: asmatrix() function

asmatrix() function

The asmatrix() function is used to interpret the input as a matrix.
Unlike matrix, asmatrix does not make a copy if the input is already a matrix or an ndarray. Equivalent to matrix(data, copy=False).

Syntax:

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

Version: 1.15.0

Parameter:

Name Description Required /
Optional
data Input data. Required
dtype Data-type of the output matrix. optional

Return value:

mat : matrix
data interpreted as a matrix.

Example-1: NumPy.asmatrix() function

>>> import numpy as np
>>> x = np.array([[1,2], [3,4]])
>>> n = np.asmatrix(x)
>>> x[0,0] = 5
>>> n
matrix([[5, 2],
        [3, 4]])

Pictorial Presentation:

NumPy array: asmatrix() function

Example-2: NumPy.asmatrix() function

>>> import numpy as np
>>> a = np.array([[2,3], [4,5]])
>>> x = np.asmatrix(a)
>>> a[0,0] = 5
>>> x
matrix([[5, 3],
        [4, 5]])

Pictorial Presentation:

NumPy array: asmatrix() function

Python - NumPy Code Editor:

Previous: ascontiguousarray()
Next: copy()