当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.ToPackedArray方法代码示例

本文整理汇总了C#中Encog.MathUtil.Matrices.Matrix.ToPackedArray方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.ToPackedArray方法的具体用法?C# Matrix.ToPackedArray怎么用?C# Matrix.ToPackedArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Encog.MathUtil.Matrices.Matrix的用法示例。


在下文中一共展示了Matrix.ToPackedArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Randomize

 public void Randomize()
 {
     const double min = 1.0;
     const double max = 10.0;
     var matrix = new Matrix(10, 10);
     matrix.Ramdomize(min, max);
     var array = matrix.ToPackedArray();
     foreach (double t in array)
     {
         if (t < min || t > max)
             Assert.IsFalse(true);
     }
 }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:13,代码来源:TestMatrix.cs

示例2: VectorLength

 /// <summary>
 /// Calculate the vector length of the matrix.
 /// </summary>
 /// <param name="input">The vector to calculate for.</param>
 /// <returns>The vector length.</returns>
 public static double VectorLength(Matrix input)
 {
     if (!input.IsVector())
     {
         throw new MatrixError(
             "Can only take the vector length of a vector.");
     }
     Double[] v = input.ToPackedArray();
     double rtn = 0.0;
     for (int i = 0; i < v.Length; i++)
     {
         rtn += Math.Pow(v[i], 2);
     }
     return Math.Sqrt(rtn);
 }
开发者ID:jongh0,项目名称:MTree,代码行数:20,代码来源:MatrixMath.cs

示例3: PackedArray

        public void PackedArray()
        {
            double[][] matrixData = {
                                        new[] {1.0, 2.0},
                                        new[] {3.0, 4.0}
                                    };
            var matrix = new Matrix(matrixData);
            double[] matrixData2 = matrix.ToPackedArray();
            Assert.AreEqual(4, matrixData2.Length);
            Assert.AreEqual(1.0, matrix[0, 0]);
            Assert.AreEqual(2.0, matrix[0, 1]);
            Assert.AreEqual(3.0, matrix[1, 0]);
            Assert.AreEqual(4.0, matrix[1, 1]);

            var matrix2 = new Matrix(2, 2);
            matrix2.FromPackedArray(matrixData2, 0);
            Assert.IsTrue(matrix.Equals(matrix2));
        }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:18,代码来源:TestMatrix.cs

示例4: DotProduct

        /// <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;
        }
开发者ID:jongh0,项目名称:MTree,代码行数:33,代码来源:MatrixMath.cs


注:本文中的Encog.MathUtil.Matrices.Matrix.ToPackedArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。