public float GetMax(FloatMatrix m) { float max = float.MinValue; MatrixLoop((i, j) => { if (m.GetValue(i, j) > max) { max = m.GetValue(i, j); } }, m.x, m.y); return(max); }
public float GetAverage(FloatMatrix m) { float d = 0; MatrixLoop((i, j) => { d += m.GetValue(i, j); }, m.x, m.y); return(d / (m.x * m.y)); }
public static FloatMatrix Pow(FloatMatrix m2, float m1) { float[,] output = new float[m2.x, m2.y]; MatrixLoop((i, j) => { output[i, j] = (float)Math.Pow(m2.GetValue(i, j), m1); }, m2.x, m2.y); return(output); }
//Operations //Transpose public static FloatMatrix Transpose(FloatMatrix m) { float[,] mT = new float[m.y, m.x]; MatrixLoop((i, j) => { mT[j, i] = m.GetValue(i, j); }, m.x, m.y); return(mT); }
//Sumatory public static FloatMatrix Sumatory(FloatMatrix m, int dimension = -1) { float[,] output; if (dimension == -1) { output = new float[1, 1]; } else if (dimension == 0) { output = new float[m.x, 1]; } else if (dimension == 1) { output = new float[1, m.y]; } else { throw new ArgumentException("The dimension must be -1, 0 or 1"); } if (dimension == -1) { MatrixLoop((i, j) => { output[0, 0] += m.GetValue(i, j); }, m.x, m.y); } else if (dimension == 0) { MatrixLoop((i, j) => { output[i, 0] += m.GetValue(i, j); }, m.x, m.y); } else if (dimension == 1) { MatrixLoop((i, j) => { output[0, j] += m.GetValue(i, j); }, m.x, m.y); } return(output); }
//Flat public FloatMatrix GetFlat(FloatMatrix m) { float[,] output = new float[m.x * m.y, 1]; MatrixLoop((i, j) => { output[m.x * i + j, 0] = m.GetValue(i, j); }, m.x, m.y); return(output); }
public static FloatMatrix DeltaMult(FloatMatrix m1, FloatMatrix m2) { if (m1.x != m2.x || m1.y != m2.y) { throw new ArgumentException("Matrix must have the same dimensions"); } float[,] output = new float[m1.x, m2.y]; MatrixLoop((i, j) => { output[i, j] = m1.GetValue(i, j) * m2.GetValue(i, j); }, m1.x, m2.y); return(output); }
public FloatMatrix AddRow(FloatMatrix m2) { if (_matrix == null) { throw new ArgumentException("Matrix can not be null"); } if (m2.x != 1 || m2.y != y) { throw new ArgumentException("Invalid dimensions"); } float[,] newMatrix = new float[x + 1, y]; float[,] m = Matrix; for (int j = 0; j < y; j++) { newMatrix[0, j] = m2.GetValue(0, j); } MatrixLoop((i, j) => { newMatrix[i + 1, j] = m[i, j]; }, x, y); return(newMatrix); }
public FloatMatrix AddColumn(FloatMatrix m2) { if (_matrix == null) { throw new ArgumentException("Matrix can not be null"); } if (m2.y != 1 || m2.x != x) { throw new ArgumentException("Invalid dimensions"); } float[,] newMatrix = new float[x, y + 1]; float[,] m = Matrix; for (int i = 0; i < x; i++) { newMatrix[i, 0] = m2.GetValue(i, 0); } MatrixLoop((i, j) => { newMatrix[i, j + 1] = m[i, j]; }, x, y); return(newMatrix); }
//ABS public FloatMatrix GetAbs(FloatMatrix m) { float[,] d = m; MatrixLoop((i, j) => { d[i, j] = Math.Abs(m.GetValue(i, j)); }, m.x, m.y); return(d); }