Tam211
Tam211

Reputation: 733

Why elements are not being inserted to the array?

This is a part of a big project I'm working on.

The problem here is in the varlist in each loop in the first for loop I insert a number that I calculate, but later when I want to make a new sorted version of this array I get this error :

 " Type mismatch: cannot convert from void to float[] " 

I can't see why I get this error, could it be because I divide a float by int?

    public static float applyVarianceFilterOnDataset(
        GeneExpressionDataset geneExpressionDataset, int numberOfGenesToKeep) {

    int rows = geneExpressionDataset.genesNumber;
    int cols = geneExpressionDataset.samplesNumber;
    float[] varlist = new float[rows];

    for (int i = 0; i < rows; i++) {
        float var = 0;
        for (int j = 0; j < cols; j++) {
            float mean = calcMean(geneExpressionDataset.dataMatrix[i], cols);
            var = (float) (Math.pow(
                    (geneExpressionDataset.dataMatrix[i][j] - mean), 2) + var);

        }
        varlist[i] = (var / cols);

    }

    float[] sortedarray = new float[rows];
    sortedarray = Arrays.sort(varlist);
    float thenum = sortedarray[rows-numberOfGenesToKeep-1];



    }

    geneExpressionDataset.genesNumber = numberOfGenesToKeep;
    return thenum;
}

public static float calcMean(float[] ary, int num) {
    float sum = 0;
    for (float i : ary) {
        sum += i;
    }
    return (sum / num);
}

Upvotes: 1

Views: 63

Answers (1)

talex
talex

Reputation: 20436

Arrays.sort(varlist) sort array inplace. So you pass it array and after method exit you array is sorted.

Upvotes: 2

Related Questions