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


C# Matrix.GetEnumerator方法代码示例

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


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

示例1: Product

        public override sealed float Product(Matrix element1, Matrix element2)
        {

            if((element1.Columns!= element2.Columns) || (element1.Rows!=element2.Rows) )
            {
                throw new RankException("Matrix have different sizes");
            }
            
            double product = 0;
            
            //(from item in element1.GetEnumerator()
            //                     let row = item.A
            //                     let col = item.B
            //                     let val = item.C
            //                     select val * element2[row, col]).Sum();

           

            foreach (var item in element1.GetEnumerator())
            {

                int row = item.A;
                int col = item.B;
                double val = item.C;

                product += val * element2[row, col];
            }
            //for (int i = 0; i <element1.Rows; i++)
            //{
            //    product += (float) element1.GetRow(i).DotProduct(element2.GetRow(i));

            //}


            return (float) product;
        }
开发者ID:maotong,项目名称:KMLib,代码行数:36,代码来源:FrobeniusKernel.cs

示例2: Main

        static void Main()
        {
            //var matrix=new Matrix(3,4);
            //for (ulong i = 0; i < matrix.RowsCount; i++)
            //    for (ulong j = 0; j < matrix.ColumnsCount; j++)
            //        matrix[i, j] = new Random(Convert.ToInt32(i)).NextDouble();
            //matrix.Transpose();
            //var matrix = new Matrix(4, 4);

            //matrix[0, 0] = 2.0;
            //matrix[0, 1] = -1.0;
            //matrix[0, 2] = 3.0;
            //matrix[0, 3] = 2.0;

            //matrix[1, 0] = 3.0;
            //matrix[1, 1] = 1.0;
            //matrix[1, 2] = 7.0;
            //matrix[1, 3] = 0.0;

            //matrix[2, 0] = -4.0;
            //matrix[2, 1] = -1.0;
            //matrix[2, 2] = 2.0;
            //matrix[2, 3] = 1.0;

            //matrix[3, 0] = -6.0;
            //matrix[3, 1] = 7.0;
            //matrix[3, 2] = 1.0;
            //matrix[3, 3] = -1.0;

               //var matrix = new Matrix(3, 3);

               // //double[,] matrix =new double[3,3];

               // matrix[0, 0] = 2.0;
               // matrix[0, 1] = 0.0;
               // matrix[0, 2] = 3.0;

               // matrix[1, 0] = 2.0;
               // matrix[1, 1] = 1.0;
               // matrix[1, 2] = 5.0;

               // matrix[2, 0] = 2.0;
               // matrix[2, 1] = 1.0;
               // matrix[2, 2] = 4.0;

               //// double[,] matrix2=MatrixOld.INV(matrix);

               // matrix.Invertible();
               // return;
            var matrix = new Matrix
            (
                new double[,]
                {
                    {1,2,0,0},
                    {4,6,0,0},
                    {7,3,0,0}
                }
            );
            IEnumerator elements = matrix.GetEnumerator();

            double[] data = new double[matrix.RowsCount*matrix.ColumnsCount];
            int i = 0;
            while (elements.MoveNext())
            {
                data[i++] = (double)elements.Current;
            }
            //matrix[0, 0] = 4.0;
            //matrix[0, 1] = 3.0;
            //matrix[0, 2] = -4.0;
            //matrix[0, 3] = 2.0;
            //matrix[0, 4] = 2.0;

            //matrix[1, 0] = 2.0;
            //matrix[1, 1] = -1.0;
            //matrix[1, 2] = -3.0;
            //matrix[1, 3] = -4.0;
            //matrix[1, 4] = 2.0;

            //matrix[2, 0] = 3.0;
            //matrix[2, 1] = 1.0;
            //matrix[2, 2] = 1.0;
            //matrix[2, 3] = 2.0;
            //matrix[2, 4] = -1.0;

            //matrix[3, 0] = 1.0;
            //matrix[3, 1] = 2.0;
            //matrix[3, 2] = 3.0;
            //matrix[3, 3] = 4.0;
            //matrix[3, 4] = -1.0;

            //matrix[4, 0] = -1.0;
            //matrix[4, 1] = 1.0;
            //matrix[4, 2] = -1.0;
            //matrix[4, 3] = -2.0;
            //matrix[4, 4] = 3.0;

               /* matrix[0, 0] = 1.0;
            matrix[0, 1] = 2.0;
            matrix[0, 2] = 0.0;
            matrix[0, 3] = 0.0;
//.........这里部分代码省略.........
开发者ID:vanderkorn,项目名称:math,代码行数:101,代码来源:Program.cs

示例3: GetEnumeratorTest

		public void GetEnumeratorTest()
		{
			IMatrix<int> matrix = new Matrix<int>(10, 10);
			int number = 0;
			for (int r = 0; r < matrix.Rows; r++)
			{
				for (int c = 0; c < matrix.Columns; c++)
				{
					matrix[r, c] = number++;
				}
			}

			number = 0;
			foreach (int i in matrix)
			{
				Assert.AreEqual(number++, i);
			}

			var en = matrix.GetEnumerator();
			number = 0;
			while (en.MoveNext())
			{
				Assert.AreEqual(number++, en.Current);
			}
		}
开发者ID:holtsoftware,项目名称:Sannel.Helpers,代码行数:25,代码来源:MatrixTests.cs


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