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)
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:
Python - NumPy Code Editor:
Previous: asanyarray()
Next: asfarray()
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/manipulation/asmatrix.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics