numl.Math.LinearAlgebra.Matrix.Reshape C# (CSharp) Method

Reshape() public static method

Reshapes the supplied matrix into a new matrix shape.
public static Reshape ( Matrix m, int rows, int cols ) : Matrix
m Matrix Matrix to reshape.
rows int Number of rows of the new matrix.
cols int Number of columns of the new matrix.
return Matrix
        public static Matrix Reshape(Matrix m, int rows, int cols)
        {
            Matrix result = new Matrix(rows, cols);

            int width = (rows > m.Rows ? m.Rows : rows);
            int height = (cols > m.Cols ? m.Cols : cols);

            for (int y = 0; y < height; y++)
                for (int x = 0; x < width; x++)
                    result[y, x] = m[y, x];

            return result;
        }

Same methods

Matrix::Reshape ( Vector v, int dimension, VectorType dimensionType = VectorType.Col, VectorType byVector = VectorType.Row ) : Matrix
Matrix::Reshape ( Vector v, int rows, int columns, VectorType byVector = VectorType.Row ) : Matrix

Usage Example

Exemplo n.º 1
0
 /// <summary>
 /// Reshapes the given Vector into a Matrix form given the specified dimension.
 /// <para>Reads from the source vector and repopulates from left to right when <paramref name="vectorType"/> equals 'Col' otherwise uses top down approach.</para>
 /// </summary>
 /// <param name="source"></param>
 /// <param name="dimension">If the <paramref name="vectorType"/> equals 'Col' the <paramref name="dimension"/> becomes the column width otherwise it is row height.</param>
 /// <param name="vectorType">Unit type of the dimension to use when rebuilding the Matrix.</param>
 /// <param name="fillType">Direction to process, i.e. Row = Fill Down then Right, or Col = Fill Right then Down</param>
 /// <returns>Matrix.</returns>
 public static Matrix Reshape(this Vector source, int dimension, VectorType vectorType = VectorType.Col, VectorType fillType = VectorType.Row)
 {
     return(Matrix.Reshape(source, dimension, vectorType, fillType));
 }