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


C# DenseMatrix.RowEnumerator方法代码示例

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


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

示例1: Run

        /// <summary>
        /// Run example
        /// </summary>
        public void Run()
        {
            // Format vector output to console
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
            formatProvider.TextInfo.ListSeparator = " ";

            // Create new empty square matrix
            var matrix = new DenseMatrix(10);
            Console.WriteLine(@"Empty matrix");
            Console.WriteLine(matrix.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 1. Fill matrix by data using indexer []
            var k = 0;
            for (var i = 0; i < matrix.RowCount; i++)
            {
                for (var j = 0; j < matrix.ColumnCount; j++)
                {
                    matrix[i, j] = k++;
                }
            }

            Console.WriteLine(@"1. Fill matrix by data using indexer []");
            Console.WriteLine(matrix.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Fill matrix by data using At. The element is set without range checking.
            for (var i = 0; i < matrix.RowCount; i++)
            {
                for (var j = 0; j < matrix.ColumnCount; j++)
                {
                    matrix.At(i, j, k--);
                }
            }

            Console.WriteLine(@"2. Fill matrix by data using At");
            Console.WriteLine(matrix.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 3. Clone matrix
            var clone = matrix.Clone();
            Console.WriteLine(@"3. Clone matrix");
            Console.WriteLine(clone.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 4. Clear matrix
            clone.Clear();
            Console.WriteLine(@"4. Clear matrix");
            Console.WriteLine(clone.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 5. Copy matrix into another matrix
            matrix.CopyTo(clone);
            Console.WriteLine(@"5. Copy matrix into another matrix");
            Console.WriteLine(clone.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 6. Get submatrix into another matrix
            var submatrix = matrix.SubMatrix(2, 2, 3, 3);
            Console.WriteLine(@"6. Copy submatrix into another matrix");
            Console.WriteLine(submatrix.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 7. Get part of the row as vector. In this example: get 4 elements from row 5 starting from column 3
            var row = matrix.Row(5, 3, 4);
            Console.WriteLine(@"7. Get part of the row as vector");
            Console.WriteLine(row.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 8. Get part of the column as vector. In this example: get 3 elements from column 2 starting from row 6
            var column = matrix.Column(2, 6, 3);
            Console.WriteLine(@"8. Get part of the column as vector");
            Console.WriteLine(column.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 9. Get columns using column enumerator. If you need all columns you may use ColumnEnumerator without parameters
            Console.WriteLine(@"9. Get columns using column enumerator");
            foreach (var keyValuePair in matrix.ColumnEnumerator(2, 4))
            {
                Console.WriteLine(@"Column {0}: {1}", keyValuePair.Item1, keyValuePair.Item2.ToString("#0.00\t", formatProvider));
            }

            Console.WriteLine();

            // 10. Get rows using row enumerator. If you need all rows you may use RowEnumerator without parameters
            Console.WriteLine(@"10. Get rows using row enumerator");
            foreach (var keyValuePair in matrix.RowEnumerator(4, 3))
            {
                Console.WriteLine(@"Row {0}: {1}", keyValuePair.Item1, keyValuePair.Item2.ToString("#0.00\t", formatProvider));
            }

            Console.WriteLine();

            // 11. Convert matrix into multidimensional array
            var data = matrix.ToArray();
            Console.WriteLine(@"11. Convert matrix into multidimensional array");
            for (var i = 0; i < data.GetLongLength(0); i++)
//.........这里部分代码省略.........
开发者ID:JohnnyPP,项目名称:TMP102,代码行数:101,代码来源:MatrixDataAccessor.cs

示例2: Run

        /// <summary>
        /// Run example
        /// </summary>
        /// <seealso cref="http://en.wikipedia.org/wiki/Matrix_norm">Matrix norm</seealso>
        public void Run()
        {
            // Format matrix output to console
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
            formatProvider.TextInfo.ListSeparator = " ";

            // Create square matrix
            var matrix = new DenseMatrix(new[,] { { 1.0, 2.0, 3.0 }, { 6.0, 5.0, 4.0 }, { 8.0, 9.0, 7.0 } });
            Console.WriteLine(@"Initial square matrix");
            Console.WriteLine(matrix.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 1. 1-norm of the matrix
            Console.WriteLine(@"1. 1-norm of the matrix");
            Console.WriteLine(matrix.L1Norm());
            Console.WriteLine();

            // 2. 2-norm of the matrix
            Console.WriteLine(@"2. 2-norm of the matrix");
            Console.WriteLine(matrix.L2Norm());
            Console.WriteLine();

            // 3. Frobenius norm of the matrix
            Console.WriteLine(@"3. Frobenius norm of the matrix");
            Console.WriteLine(matrix.FrobeniusNorm());
            Console.WriteLine();

            // 4. Infinity norm of the matrix
            Console.WriteLine(@"4. Infinity norm of the matrix");
            Console.WriteLine(matrix.InfinityNorm());
            Console.WriteLine();

            // 5. Normalize matrix columns
            Console.WriteLine(@"5. Normalize matrix columns: before normalize");
            foreach (var keyValuePair in matrix.ColumnEnumerator())
            {
                Console.WriteLine(@"Column {0} 2-nd norm is: {1}", keyValuePair.Item1, keyValuePair.Item2.Norm(2));
            }

            Console.WriteLine();
            var normalized = matrix.NormalizeColumns(2);
            Console.WriteLine(@"5. Normalize matrix columns: after normalize");
            foreach (var keyValuePair in normalized.ColumnEnumerator())
            {
                Console.WriteLine(@"Column {0} 2-nd norm is: {1}", keyValuePair.Item1, keyValuePair.Item2.Norm(2));
            }

            Console.WriteLine();

            // 6. Normalize matrix columns
            Console.WriteLine(@"6. Normalize matrix rows: before normalize");
            foreach (var keyValuePair in matrix.RowEnumerator())
            {
                Console.WriteLine(@"Row {0} 2-nd norm is: {1}", keyValuePair.Item1, keyValuePair.Item2.Norm(2));
            }

            Console.WriteLine();
            normalized = matrix.NormalizeRows(2);
            Console.WriteLine(@"6. Normalize matrix rows: after normalize");
            foreach (var keyValuePair in normalized.RowEnumerator())
            {
                Console.WriteLine(@"Row {0} 2-nd norm is: {1}", keyValuePair.Item1, keyValuePair.Item2.Norm(2));
            }
        }
开发者ID:Mistrall,项目名称:Solvation,代码行数:68,代码来源:MatrixNorms.cs


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