Python | Numpy matrix.tostring() (original) (raw)
Last Updated : 29 May, 2019
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 are able to find the byte code in string format for the given matrix.
import
numpy as np
gfg
=
np.matrix(
'[4, 1; 12, 3]'
)
geek
=
gfg.tostring()
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.tostring()
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.tobytes() 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 cod 1 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
- Python | Numpy matrix.setfield() With the help of matrix.setfield() method, all the fields in the matrix is set to the value which is passed in the form of parameter. Syntax : matrix.setfield() Return : new matrix having the value passed as parameter Example #1 : In this example we can see that matrix.setfield() method is used to g 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.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
- 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.array_str() in Python numpy.array_str()function is used to represent the data of an array as a string. The data in the array is returned as a single string. This function is similar to array_repr, the difference being that array_repr also returns information on the kind of array and its data type. Syntax : numpy.array_st 2 min read
- numpy.rint() in Python The numpy.rint() is a mathematical function that rounds elements of the array to the nearest integer. Syntax : numpy.rint(x[, out]) = ufunc ‘rint’) Parameters : array : [array_like] Input array. Return : An array with all array elements being rounded off, having same type and shape as input. Code #1 2 min read