/// <summary> /// /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="operation"></param> /// <returns></returns> public static float[][] ElementWiseOperation(float[][] a, float[][] b, ElementWiseOperation operation) { if (!MatrixCompare.SameSize(a, b)) { throw new ArgumentException("Matrices are not of same size."); } float[][] y = CreateMatrix(Rows(a), Columns(b)); for (int i = 0; i < Rows(y); i++) { y[i] = VectorMath.ElementWiseOperation(a[i], b[i], operation); } return(y); }
/// <summary> /// Element-wise subtraction. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static float[][] Subtract(float[][] a, float[][] b) { if (!MatrixCompare.SameSize(a, b)) { throw new ArgumentException("Matrices are not of same size."); } float[][] y = CreateMatrix(Rows(a), Columns(a)); for (int i = 0; i < Rows(y); i++) { y[i] = VectorMath.Subtract(Row(a, i), Row(b, i)); } return(y); }
/// <summary> /// Multiply two matrices. /// </summary> /// <param name="a">matrix a</param> /// <param name="b">matrix b</param> /// <returns>a new matrix which is the result of the multiplication</returns> public static float[][] Multiply(float[][] a, float[][] b) { float[][] y = CreateMatrix(Rows(a), Columns(b)); float[][] bt = Transpose(b); if (!MatrixCompare.CompareColumnsWithRows(a, b)) { throw new ArgumentException("Illegal matrix dimensions."); } for (int r = 0; r < Rows(a); r++) { for (int c = 0; c < Columns(b); c++) { float[] ra = Row(a, r); float[] rb = Row(bt, c); y[r][c] = VectorMath.Dot(ra, rb); } } return(y); }