本文介绍了Scalala是否提供将向量插入矩阵的直接方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有可用的运算符中我有些失落了-那么是否有简单的方法将整个行/列(向量)插入矩阵?

I am a bit lost among all those available operators -- so is there easy way to insert a entire row/column (vector) into a matrix?

我开始考虑创建向量,将其转换为数组,将其与转换为数组的矩阵结合起来,并基于这种组合数组创建新矩阵,但是看起来比实际听起来还要难看.

I started thinking about creating a vector, converting it to array, joining it with matrix converted into array, and creating new matrix based on such combined array, but it looks even uglier than it sounds.

推荐答案

val m = DenseMatrix((1, 4, 10, 13), (2, 5, 11, 14), (3, 6, 12, 15))

val v = DenseVector(7, 8, 9)

val m2 = DenseMatrix.zeros[Int](3, 5)
m2(::, 0 to 1) := m(::, 0 to 1)
m2(::, 2) := v
m2(::, 3 to 4) := m(::, 2 to 3)

您将找到有关基本清风功能此处.

You'll find more information about basic breeze functionality here.

这篇关于Scalala是否提供将向量插入矩阵的直接方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 09:04