/// <summary> /// Performs an element wise operation on the input Matrix. /// </summary> /// <param name="m">Matrix.</param> /// <param name="fnElementWiseOp">Function to update each cell specified by the value and cell coordinates.</param> /// <returns>A Matrix.</returns> public static Matrix Each(Matrix m, Func <double, int, int, double> fnElementWiseOp) { var copy = m.ToArray(); for (int i = 0; i < m.Rows; i++) { for (int j = 0; j < m.Cols; j++) { copy[i][j] = fnElementWiseOp(copy[i][j], i, j); } } return(copy); }
/// <summary> /// Performs an element-wise operation on the input Matrices. /// </summary> /// <param name="m1">First Matrix.</param> /// <param name="m2">Second Matrix.</param> /// <param name="fnElementWiseOp">Operation to perform on the value from the first and second matrices.</param> /// <returns>A Matrix.</returns> public static Matrix Each(Matrix m1, Matrix m2, Func <double, double, double> fnElementWiseOp) { if (m1.Rows != m2.Rows) { throw new InvalidOperationException("The row dimensions do not match"); } if (m1.Cols != m2.Cols) { throw new InvalidOperationException("The column dimensions do not match"); } var copy = m1.ToArray(); for (int i = 0; i < m1.Rows; i++) { for (int j = 0; j < m1.Cols; j++) { copy[i][j] = fnElementWiseOp(m1[i, j], m2[i, j]); } } return(copy); }
/// <summary> /// Performs an element-wise operation on the input Matrices. /// </summary> /// <param name="m1">First Matrix.</param> /// <param name="m2">Second Matrix.</param> /// <param name="fnElementWiseOp">Operation to perform on the value from the first and second matrices.</param> /// <returns>A Matrix.</returns> public static Matrix Each(Matrix m1, Matrix m2, Func<double, double, double> fnElementWiseOp) { if (m1.Rows != m2.Rows) throw new InvalidOperationException("The row dimensions do not match"); if (m1.Cols != m2.Cols) throw new InvalidOperationException("The column dimensions do not match"); var copy = m1.ToArray(); for (int i = 0; i < m1.Rows; i++) { for (int j = 0; j < m1.Cols; j++) { copy[i][j] = fnElementWiseOp(m1[i, j], m2[i, j]); } } return copy; }
/// <summary> /// Performs an element wise operation on the input Matrix. /// </summary> /// <param name="m">Matrix.</param> /// <param name="fnElementWiseOp">Function to update each cell specified by the value and cell coordinates.</param> /// <returns>A Matrix.</returns> public static Matrix Each(Matrix m, Func<double, int, int, double> fnElementWiseOp) { var copy = m.ToArray(); for (int i = 0; i < m.Rows; i++) { for (int j = 0; j < m.Cols; j++) { copy[i][j] = fnElementWiseOp(copy[i][j], i, j); } } return copy; }