如何在 Scala 中将一个矩阵附加到另一个矩阵?
如果我有以下代码:
var A = Array[Array[Double]]() // where A becomes an MxP matrix
var B = Array[Array[Double]]() // where B becomes an NxP matrix
有哪些有效的方法可以将一个矩阵附加到另一个矩阵,从而产生单个矩阵,如以下伪代码所示?
val C = A append B // where C is a (M+N)xP matrix
显然,其中一个维度(在本例中为 P)保持不变。
编辑:到目前为止,提供的两个解决方案都在第二维度上增长。我试图保持第二个维度固定。
If I have the following code:
var A = Array[Array[Double]]() // where A becomes an MxP matrix
var B = Array[Array[Double]]() // where B becomes an NxP matrix
What are some efficient ways to append one matrix to the other, resulting in a single matrix, as the following pseudocode would suggest?
val C = A append B // where C is a (M+N)xP matrix
Obviously, one of the dimensions (in this case P) is held constant.
EDIT: So far, both of the provided solutions are growing in the second dimension. I am trying to hold the second dimension fixed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
功能性,但不如命令式替代方案那样高效:(
回复评论...)
固定第二个维度:
Functional, but not as performant as the imperative alternative would be:
(In reply to the comment...)
Holding the second dimension fixed: