w3resource

NumPy: numpy.asmatrix() function

numpy.asmatrix() function

The numpy.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).

Syntax:

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

Parameters:

Name Description Required /
Optional
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()



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://www.w3resource.com/numpy/manipulation/asmatrix.php