-1

我正在从事一个处理大型数据矩阵的项目。当我尝试将其标准化以进行计算时,出现错误

operator - is undefined for argument types double[]

我的代码如下:

import Jama.*;

public static Matrix normalize(Matrix ip_matrix, double[][] min_bound, double[][] max_bound)
{
    Matrix mat = ip_matrix.transpose();
    double[][] mat1 = mat.getArray(); // getting matrix as an array to perfom the computation.
    int nb_input = mat1[0].length;
    double[][] norm = new double[mat1[0].length][mat1[1].length]; // Initialize a default array to store the output, in the required dimension.

    for (int i = 0; i <= nb_input; i++)
    {
        norm[i] = (mat1[i] - min_bound[i] / (max_bound[i] - min_bound[i])); //The line where i get the error.

    }
    norm = norm.getMatrix();
    return norm;
    }

我基本上是一名 Python 程序员,并且相同的逻辑在我的 Python 代码中运行良好。我在 python 中使用 numpy。并在 java 中使用 JAMA 库。

我只是java的初学者,所以请任何指导都会受到高度赞赏。

4

1 回答 1

1

您正在创建一个二维数组,也就是一个矩阵。在 Java 中,没有真正的二维数组。您在这里所做的是创建一个doubles 数组的数组。

因此,当您使用[]运算符访问数组时,您实际上得到的是doubles 的一维数组。当你[][]用来访问它时,你会得到一个double. 所以这就是你得到错误的原因。您使用单个[]来访问它,然后对它们进行减法运算。

于 2015-10-27T11:07:25.040 回答