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

标签 java matrix octave matrix-multiplication blas

我正在使用 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/

相关文章:

java - java中如何获取总时间?

java - 如何在catalina.out中显示上下文的名称?

matlab - 将所有非零矩阵元素设置为 1(同时保持其他元素为 0)

java - 从Java到C的矩阵转置移植,类型不兼容的问题

matlab - 在 Matlab/Octave 矩阵中使用范围

java - FirestoreRecyclerAdapter中实现onClick打开新的Activity

java - 使用 fragment 事务的 NullPointerException

python - 点乘不同 dtype 的大密集矩阵(float x boolean)

python - 神经网络 Octave 实现

octave - Octave中有倒数函数吗?