javamatrixnormalizationjama

operator - undefined for argument types double[]


I am working on a project which deals with large matrices of data. When i try to normalize it for my computation, I get the error

operator - is undefined for argument types double[]

my code is as follows:

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;
    }

I am basically a python programmer and the same logic works fine in my python codes. I use numpy in python. and am using JAMA library in java for the same.

I am just a beginner in java, so please any guidance would be highly aprreciated.


Solution

  • You are creating a 2D array aka a matrix. In Java, there isn't really 2D arrays. What you are doing here is creating an array of arrays of doubles.

    So when you use the [] operator to access the array, you are actually getting a 1D array of doubles. When you use [][] to access it, you get a double. So that's why you get the error. You use a single [] to access it and you do subtraction on them.