Python Numpy matrix.tostring()

Python Numpy matrix.tostring()

Numpy matrix.tostring()方法的帮助下,我们可以通过matrix.tostring()方法找到矩阵的字符串格式的字节码。

语法: matrix.tostring()
返回: 返回矩阵的字节码字符串

例子#1 :
在这个例子中,我们可以看到,通过使用matrix.tostring()方法,我们能够找到给定矩阵的字符串格式的字节码。

# import the important module in python
import numpy as np
              
# make matrix with numpy
gfg = np.matrix('[4, 1; 12, 3]')
              
# applying matrix.tostring() method
geek = gfg.tostring()
    
print(geek)

输出:

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′

例子#2 :

# import the important module in python
import numpy as np
              
# make matrix with numpy
gfg = np.matrix('[4, 1, 9; 12, 3, 1; 4, 5, 6]')
              
# applying matrix.tostring() method
geek = gfg.tostring()
    
print(geek)

输出:

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′

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程