Python:矩阵列表到numpy数组? [英] python: list of matrices to numpy array?

查看:117
本文介绍了Python:矩阵列表到numpy数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含numpy矩阵的列表.无论如何,我可以将整个东西变成一个干净的numpy数组?

I've got a list containing numpy matrices. Anyway that I could turn the whole thing into a nice clean numpy array?

发件人:

[matrix([[1]]), matrix([[ 1.99387871]]), matrix([[ 2.53564618]]), matrix([[ 4.39125807]]), matrix([[ 4.246309]]), matrix([[ 5.21571607]]), matrix([[ 6.17408811]]), matrix([[ 4.75146571]]), matrix([[ 6.19319742]]), matrix([[ 6.1277607]]), matrix([[ 7.43821216]])]

收件人:

[[1 1.99387871 2.53564618 4.39125807 4.246309 5.21571607 6.17408811 4.75146571 6.19319742 6.1277607 7.43821216]]

推荐答案

b = np.asarray(a, dtype=float)
#to get the same shape do.
b = b.reshape(-1, len(b)) 
#to just get one dimmension do. 
b = np.asarray(a, dtype=float).reshape(len(a))

这篇关于Python:矩阵列表到numpy数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆