NumPy Array manipulation: asmatrix() function

numpy.asmatrix() function

The asmatrix() function is used to interpret an given 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).


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

Version: 1.15.0


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

Return value:

mat [matrix] data interpreted as a matrix.

Example: numpy.asmatrix()

>>> import numpy as np
>>> y = np.array([[3, 4], [5, 6]])
>>> z = np.asmatrix(y)
>>> y[0,0] = 8
>>> z
matrix([[8, 4],
        [5, 6]])

Pictorial Presentation:

NumPy manipulation: asmatrix() function

Python - NumPy Code Editor:

Previous: asanyarray()
Next: asfarray()