numpy.matrix() in Python (original) (raw)
Last Updated : 09 Mar, 2022
This class returns a matrix from a string of data or array-like object. Matrix obtained is a specialised 2D array.
Syntax :
numpy.matrix(data, dtype = None) :
Parameters :
data : data needs to be array-like or string dtype : Data type of returned array.
Returns :
data interpreted as a matrix
import
numpy as geek
a
=
geek.matrix(
'1 2; 3 4'
)
print
(
"Via string input : \n"
, a,
"\n\n"
)
b
=
geek.matrix([[
5
,
6
,
7
], [
4
,
6
]])
print
(
"Via array-like input : \n"
, b)
Output :
Via string input : [[1 2] [3 4]]
Via array-like input : [[[5, 6, 7] [4, 6]]]
References :
https://docs.scipy.org/doc/numpy/reference/generated/numpy.mat.html#numpy.mat
Note :
These codes won’t run on online IDE’s. Please run them on your systems to explore the working
.
Similar Reads
- Python | Numpy matrix.item() With the help of Numpy matrix.item() method, we can get the items from a given matrix by just providing index number and for multidimensional matrix we get the item by giving tuple of index value. Syntax : matrix.item(index) Return : Return item from given matrix Example #1 : In this example we can 1 min read
- Python | Numpy matrix.fill() With the help of Numpy matrix.fill() method, we are able to fill a scalar value in a given matrix and gives output as matrix having scalar values. Syntax : matrix.fill(value) Return : Return a matrix having scalar value Example #1 : In this example we can see that with the help of matrix.fill() meth 1 min read
- Python | Numpy matrix.dot() With the help of Numpy matrix.dot() method, we are able to find a product of two given matrix and gives output as new dimensional matrix. Syntax : matrix.dot() Return : Return product of two matrix Example #1 : In this example we can see that with the help of matrix.dot() method we are able to find 1 min read
- Python | Numpy matrix.diagonal() With the help of Numpy matrix.diagonal() method, we are able to find a diagonal element from a given matrix and gives output as one dimensional matrix. Syntax : matrix.diagonal() Return : Return diagonal element of a matrix Example #1 : In this example we can see that with the help of matrix.diagona 1 min read
- Python | Numpy matrix.getA() With the help of Numpy matrix.getA() method, we can get the ndarray of the same size as of our given matrix. Syntax : matrix.getA() Return : Return ndarray of same size as given matrix Example #1 : In this example we can see that we are able to get the numpy array with the help of method matrix.getA 1 min read
- Python | Numpy matrix.copy() With the help of Numpy matrix.copy() method, we can make a copy of all the data elements that is present in matrix. If we change any data element in the copy, it will not affect the original matrix. Syntax : matrix.copy() Return : Return copy of matrix Example #1 : In this example we can see that wi 1 min read
- Python | Numpy matrix.flatten() With the help of Numpy matrix.flatten() method, we are able to flatten of a given matrix and gives output as one dimensional matrix. Syntax : matrix.flatten() Return : Return flatten 1-D matrix Example #1 : In this example we can see that with the help of matrix.flatten() method we are able to flatt 1 min read
- numpy.mean() in Python numpy.mean(arr, axis = None) : Compute the arithmetic mean (average) of the given data (array elements) along the specified axis. Parameters : arr : [array_like]input array. axis : [int or tuples of int]axis along which we want to calculate the arithmetic mean. Otherwise, it will consider arr to be 2 min read
- numpy.matrix.A() function - Python numpy.matrix.A() function return self as an ndarray object. Syntax : numpy.matrix.A() Parameters : None Return : [ndarray] Return self as an ndarray. Code #1 : # Python program explaining # numpy.matrix.A() function # importing numpy as geek import numpy as geek mat = geek.matrix(geek.arange(9).resh 1 min read
- Python | Numpy matrix.getA1() With the help of Numpy matrix.getA1() method, we can get the ndarray of one dimension as of our given matrix. Syntax : matrix.getA1() Return : Return ndarray of size 1-D as given matrix Example #1 : In this example we can see that we are able to get the numpy array with the help of method matrix.get 1 min read