Calculating media, using sort
in
Programming Questions
•
1 year ago
Hello,
(I'm still a beginner) I'm trying to think of an efficient way to calculate median values for a lot of data. I need to ignore zero values and only calculate the median of the non-zero values. I don't think I'm using sort correctly, nor does this seem like an efficient approach in general. I have 2 questions:
1. Why does this code return "[F@1fcabd4" in the print statement for each entry in median?
2. Is there a more efficient way to do this overall?
Thanks!
- void meanMedian(boolean leftRight) {
- if (!leftRight) {
- median = new float[totalSeconds + 86400];
- for (int i = 0; i < totalDays; i ++) {
- int skipped = 0;
- float [] edaToday = new float[86400];
- for (int p = 0; p < 86400; p++) {
- edaToday[p] = totalEda[i*86400 + p];
- if (totalEda[i*86400 + p] == 0) {
- skipped ++;
- }
- }
- sort(edaToday);
- reverse(edaToday);
- sort(edaToday, 86400-skipped);
- float [] medianArray = new float[86400 - skipped];
- medianArray = sort(edaToday, 86400-skipped);
- median[i] = medianArray[86400/2];
- println("median day " + i + " = " + median);
- }
- }
- }
1