Let's say I have 3 functions, something like y_1(x) = x^2, y_2(x) = x+1 and y_3(x) = x/5.
How do I apply these functions to any multidimensional float array in an element wise fashion?
Now given that I have the functions y_1, y_2 and y_3, what is a function that applies an arbitrary function to a float array of any size and shape?
I tried creating a function applier that takes in any function and then applying it to every element in a double loop for the 2 dimensional case but I cannot even get the function applier to take another function as input.
I tried doing the following
public float[][] elemen_wise_function( float[][] x,
int Size_axis_0,
int Size_axis_1,
Callable<> myFunc) {
float[][] Constructed_array = new float[Size_axis_0][Size_axis_1];
for (int i=0; i<Size_axis_0; i++) {
for (int j = 0; j < Size_axis_1; j++) {
Constructed_array[i][j] = (float) myFunc(x[i][j]) ;
}
}
return Constructed_array;
}
But this fails because I cannot find a way to pass myFunc to elemen_wise_function.
mapis the typical function to do this, although you'll need to use streams for that in Java. You could also just loop over the array using a standardforloop, and produce a new array using the loop.Arrays.map? possible duplicate of stackoverflow.com/a/3907448/10625458Functiontype. This question is a little broad though, as there's many ways to do what you're asking.