Stack() public static method

Stack a set of vectors into a matrix.
public static Stack ( ) : Matrix
return Matrix
コード例 #1
0
ファイル: VectorExtensions.cs プロジェクト: toroerp/numl
        /// <summary>
        /// An IEnumerable&lt;double[]&gt; extension method that converts the source into a matrix.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="source">The source to act on.</param>
        /// <param name="vectorType">The <see cref="VectorType"/> of the input array.</param>
        /// <returns>e as a Matrix.</returns>
        public static Matrix ToMatrix(this IEnumerable <Vector> source, VectorType vectorType = VectorType.Row)
        {
            var c = source.Count();

            if (c == 0)
            {
                throw new InvalidOperationException("Cannot create matrix from an empty set.");
            }

            return(Matrix.Stack(vectorType, source.ToArray()));
        }
コード例 #2
0
        /// <summary>
        /// Slices the Matrix returning only the cells specified by their location.
        /// </summary>
        /// <param name="m">Matrix.</param>
        /// <param name="indices">An 2-D location array of indexes to include.</param>
        /// <param name="t">Type of the first dimension in the location array.</param>
        /// <returns></returns>
        public static Matrix Slice(this Matrix m, IEnumerable <IEnumerable <int> > indices, VectorType t = VectorType.Row)
        {
            List <Vector> vectors = new List <Vector>();

            int top = (t == VectorType.Row ? m.Rows : m.Cols);

            for (int i = 0; i < top; i++)
            {
                vectors.Add(m[i, t].Slice(indices.ElementAt(i)));
            }

            return(Matrix.Stack(t, vectors.ToArray()));
        }
コード例 #3
0
ファイル: MatrixStatics.cs プロジェクト: toroerp/numl
 /// <summary>Stack a set of vectors into a matrix.</summary>
 /// <param name="vectors">.</param>
 /// <returns>A Matrix.</returns>
 public static Matrix Stack(params Vector[] vectors)
 {
     return(Matrix.Stack(VectorType.Row, vectors));
 }
コード例 #4
0
 /// <summary>A Matrix extension method that stacks.</summary>
 /// <param name="m">Matrix.</param>
 /// <param name="t">Row or Column sum.</param>
 /// <returns>A Matrix.</returns>
 public static Matrix Stack(this Matrix m, Matrix t)
 {
     return(Matrix.Stack(m, t));
 }