使用Scala中现有的列表列表创建Breeze DenseMatrix [英] Creating a Breeze DenseMatrix using an existing List of Lists in Scala

查看:191
本文介绍了使用Scala中现有的列表列表创建Breeze DenseMatrix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个

List[List[Int]] = List(List(1, 2, 3, 0, 0, 0, 0, 0, 0), List(0, 0, 0, 1, 2, 3, 0, 0, 0), List(0, 0, 0, 0, 0, 0, 1, 2, 3))

,我想创建一个3行9列的Matrix/DenseMatrix,以便可以对其执行一些线性代数运算.

and I want to create a Matrix/DenseMatrix with 3 rows and 9 columns so that I can perform some Linear Algebra operations on it.

推荐答案

目前还没有很好的语法.我实际上今天遇到了它,因此我可能会很快为其添加更好的支持.同时,DenseMatrix(array1,array2,array3)工作.所以:

There's not great syntax for this yet. I actually ran into it today, so I'll probably add better support for it soon. In the meantime, DenseMatrix(array1, array2, array3) works. So:

val listOfLists : List[List[Int]] = ???

DenseMatrix(listOfLists.map(_.toArray):_*)

不是最漂亮的,但是如果您打开票证,我会提供更好的支持.

Not the prettiest, but I'll add better support if you open a ticket.

这篇关于使用Scala中现有的列表列表创建Breeze DenseMatrix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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