python矩阵转换为一维数组

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lql0716/article/details/52595590

python矩阵转换为一维数组


author@jason_ql
http://blog.csdn.net/lql0716


>>>from compiler.ast import flatten

>>>X
matrix([[  1,  17,  13, 221, 289, 169],
        [  1,  17,  14, 238, 289, 196],
        [  1,  17,  15, 255, 289, 225],
        [  1,  18,  13, 234, 324, 169],
        [  1,  18,  14, 252, 324, 196],
        [  1,  18,  15, 270, 324, 225],
        [  1,  19,  13, 247, 361, 169],
        [  1,  19,  14, 266, 361, 196],
        [  1,  19,  15, 285, 361, 225]])
>>>x = X.tolist()
>>>x
[[  1,  17,  13, 221, 289, 169],
        [  1,  17,  14, 238, 289, 196],
        [  1,  17,  15, 255, 289, 225],
        [  1,  18,  13, 234, 324, 169],
        [  1,  18,  14, 252, 324, 196],
        [  1,  18,  15, 270, 324, 225],
        [  1,  19,  13, 247, 361, 169],
        [  1,  19,  14, 266, 361, 196],
        [  1,  19,  15, 285, 361, 225]]
>>>xx = flatten(x)
>>>xx
[1,
 17,
 13,
 221,
 289,
 169,
 1,
 17,
 14,
 238,
 289,
 196,
 1,
 17,
 15,
 255,
 289,
 225,
 1,
 18,
 13,
 234,
 324,
 169,
 1,
 18,
 14,
 252,
 324,
 196,
 1,
 18,
 15,
 270,
 324,
 225,
 1,
 19,
 13,
 247,
 361,
 169,
 1,
 19,
 14,
 266,
 361,
 196,
 1,
 19,
 15,
 285,
 361,
 225]

干货分享

没有更多推荐了,返回首页