Encog.MathUtil.Matrices.Matrix.ToPackedArray C# (CSharp) Method

ToPackedArray() public method

Convert the matrix to a packed array.
public ToPackedArray ( ) : double[]
return double[]
        public double[] ToPackedArray()
        {
            var result = new double[Rows*Cols];

            int index = 0;
            for (int r = 0; r < Rows; r++)
            {
                for (int c = 0; c < Cols; c++)
                {
                    result[index++] = matrix[r][c];
                }
            }

            return result;
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Compute the dot product for two matrixes.  Note: both matrixes must be vectors.
        /// </summary>
        /// <param name="a">The first matrix, must be a vector.</param>
        /// <param name="b">The second matrix, must be a vector.</param>
        /// <returns>The dot product of the two matrixes.</returns>
        public static double DotProduct(Matrix a, Matrix b)
        {
            if (!a.IsVector() || !b.IsVector())
            {
                throw new MatrixError(
                          "To take the dot product, both matrixes must be vectors.");
            }

            Double[] aArray = a.ToPackedArray();
            Double[] bArray = b.ToPackedArray();

            if (aArray.Length != bArray.Length)
            {
                throw new MatrixError(
                          "To take the dot product, both matrixes must be of the same length.");
            }

            double result = 0;
            int    length = aArray.Length;

            for (int i = 0; i < length; i++)
            {
                result += aArray[i] * bArray[i];
            }

            return(result);
        }
All Usage Examples Of Encog.MathUtil.Matrices.Matrix::ToPackedArray