Python | Numpy matrix.tobytes() (original) (raw)
Last Updated : 29 May, 2019
With the help of **Numpy matrix.tobytes()**
method, we can find the byte code for the matrix by using the matrix.tobytes()
method.
Syntax :
matrix.tobytes()
Return : Return byte code for matrix
Example #1 :
In this example we can see that by using **matrix.tobytes()**
method we are able to find the byte code for the given matrix.
import
numpy as np
gfg
=
np.matrix(
'[4, 1; 12, 3]'
)
geek
=
gfg.tobytes()
print
(geek)
Output:
b’\x04\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00′
Example #2 :
import
numpy as np
gfg
=
np.matrix(
'[4, 1, 9; 12, 3, 1; 4, 5, 6]'
)
geek
=
gfg.tobytes()
print
(geek)
Output:
b’\x04\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00′
Similar Reads
- Python | Numpy matrix.tolist() With the help of Numpy matrix.tolist() method, we are able to convert the matrix into a list by using the matrix.tolist() method. Syntax: matrix.tolist() Return : Return a new list Example #1 : In this example we can see that by passing the matrix we are able to convert it into list by using the mat 1 min read
- Python | Numpy matrix.take() With the help of Numpy matrix.take() method, we can select the elements from a given matrix by passing the parameter as index value of that element. It will return a matrix having one dimension. Remember it will work for one axis at a time. Syntax : matrix.take(index, axis) Return : Return matrix of 1 min read
- Python | Numpy matrix.tostring() With the help of Numpy matrix.tostring() method, we can find the byte code in string format for the matrix by using the matrix.tostring() method. Syntax : matrix.tostring() Return : Return byte code string for matrix Example #1 : In this example we can see that by using matrix.tostring() method we a 1 min read
- Python | Numpy matrix.sum() With the help of matrix.sum() method, we are able to find the sum of values in a matrix by using the same method. Syntax : matrix.sum() Return : Return sum of values in a matrix Example #1 : In this example we are able to find the sum of values in a matrix by using matrix.sum() method. # import the 1 min read
- Python | Numpy matrix.transpose() With the help of Numpy matrix.transpose() method, we can find the transpose of the matrix by using the matrix.transpose()method in Python. Numpy matrix.transpose() Syntax Syntax : matrix.transpose() Parameter: No parameters; transposes the matrix it is called on. Return : Return transposed matrix Wh 3 min read
- Python | Numpy matrix.round() With the help of Numpy matrix.round() method, we are able to round off the values of the given matrix. Syntax : matrix.round() Return : Return rounded values in matrix Example #1 : In the given example we are able to round off the given matrix by using matrix.round() method. # import the important m 1 min read
- numpy.matrix() in Python 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 # Pytho 1 min read
- Python | Numpy numpy.matrix.T() With the help of Numpy numpy.matrix.T() method, we can make a Transpose of any matrix either having dimension one or more than more. Syntax : numpy.matrix.T() Return : Return transpose of every matrix Example #1 : In this example we can see that with the help of matrix.T() method, we are able to tra 1 min read
- numpy.asmatrix() in Python numpy.asmatrix(data, dtype = None) Returns a matrix by interpreting the input as a matrix. Parameters : data : array-like input data dtype : Data type of returned array Returns : Interprets the input as a matrix # Python Programming illustrating # numpy.asmatrix import numpy as geek # array-like inp 1 min read
- Numpy ndarray.tobytes() function | Python numpy.ndarray.tobytes() function construct Python bytes containing the raw data bytes in the array. Syntax : numpy.ndarray.tobytes(order='C') Parameters : order : [{‘C’, ‘F’, None}, optional] Order of the data for multidimensional arrays: C, Fortran, or the same as for the original array. Return : P 1 min read