gpt4 book ai didi

java - 使用 Jblas : Matrices need to have same length 的矩阵乘法

转载 作者:行者123 更新时间:2023-11-30 08:12:23 45 4
gpt4 key购买 nike

我正在使用 Java + Jblas(首次使用)并尝试将两个矩阵相乘。一个是 163x4,另一个是 4x1 矩阵。我希望这种乘法的结果是一个 163x1 矩阵。但是使用:

FloatMatrix a = b.mmuli(c);

我收到错误:

Matrices must have same length (is: 652 and 4)

虽然我认为这对我感到困惑的程序来说非常有意义。同样的乘法在 Octave 中运行良好(当然应用了一些魔法)。但现在要让它发挥作用,我需要知道这是一种什么样的魔法?

编辑

Octave 文档中关于广播(魔法)的内容如下:

In case all dimensions are equal, no broadcasting occurs and ordinary element-by-element arithmetic takes place. For arrays of higher dimensions, if the number of dimensions isn’t the same, then missing trailing dimensions are treated as 1. When one of the dimensions is 1, the array with that singleton dimension gets copied along that dimension until it matches the dimension of the other array.

所以这意味着我只需复制 4x1 矩阵 163 次。然后我可以执行乘法,但我现在有一个 163x4 矩阵,而不是我想要的 163x1 矩阵。这对我来说很奇怪。我现在的解决方案是什么?

最佳答案

所以我终于想通了。这是其中一个错误......必须是

FloatMatrix a = b.mmul(c);

元素乘法是这里的错误。

关于java - 使用 Jblas : Matrices need to have same length 的矩阵乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30535159/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com