i was wondering how to create a copy and return its object without using the clone function.
public double[] Mean(double[][] data) {
double[] x = data[0].clone();
i was wondering how to create a copy and return its object without using the clone function.
public double[] Mean(double[][] data) {
double[] x = data[0].clone();
You can use this:
double copy = Arrays.copyOf(data[0],data[0].length);
Which will, as the name states, return a copy
of the array.
NOTE: this will only work for arrays, since it's a method from java.util.Arrays
(self-explanatory)
public double[] colMean(double[][] data) {
double[] x = new double[data[0].length];
for (int i = 0; i < x.length; i++) {
x[i] = data[0][i];
}
return x;
}
Odd that you only want to copy data[0] though, but whatever...