这篇文章主要介绍了如何在python中将矩阵转换为一维数组,天达云小编觉得不错,现在分享给大家,也给大家做个参考,一起跟随天达云小编来看看吧!
Python主要用来做什么
Python主要应用于:1、Web开发;2、数据科学研究;3、网络爬虫;4、嵌入式应用开发;5、游戏开发;6、桌面应用开发。
实例如下所示:
>>>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]
以上就是天达云小编为大家收集整理的如何在python中将矩阵转换为一维数组,如何觉得天达云网站的内容还不错,欢迎将天达云网站推荐给身边好友。