map method
Calls f
for each element in the matrix and stores the result in a new matrix.
Matrix a = Matrix.eye(3)
a.map( (double v) {
return v*v;
});
print(a)
with print
[[ 9.0, 0.0, 0.0], [0.0, 9.0, 0.0], [0.0, 0.0, 9.0]]
Implementation
Matrix map(MatrixMapFunc f) {
Matrix toReturn = new Matrix.fill(m, n);
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
toReturn[i][j] = f(this[i][j]);
}
}
return toReturn;
}