當前位置: 首頁>>代碼示例>>C#>>正文


C# DataTable.ToMatrix方法代碼示例

本文整理匯總了C#中System.Data.DataTable.ToMatrix方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.ToMatrix方法的具體用法?C# DataTable.ToMatrix怎麽用?C# DataTable.ToMatrix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Data.DataTable的用法示例。


在下文中一共展示了DataTable.ToMatrix方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Build_Corr_Matrix

        void Build_Corr_Matrix(DataTable tempdt)
        {
            for (int i = 0; i < tempdt.Columns.Count; i++)
            {
                string type = tempdt.Columns[i].DataType.ToString();
                if ((type.Contains(typeof(string).ToString()) || type.Contains(typeof(char).ToString())))
                {
                    tempdt.Columns.Remove(tempdt.Columns[i]);
                }
                else
                {
                    foreach (DataRow dr in tempdt.Rows)
                    {
                        if (dr[i].GetType().ToString().Contains("DBNull"))
                        {
                            dr[i] = 0.0;
                        }
                    }
                }
            }

            double[,] tableMatrix = tempdt.ToMatrix();
            double[,] correlMatrix = Accord.Statistics.Tools.Correlation(tableMatrix);
            string[] names = new string[tempdt.Columns.Count];
            int h = 0;
            TableRow headRow = new TableRow();

            TableCell cornerCell = new TableCell();
            cornerCell.Text = "-";
            cornerCell.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
            cornerCell.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
            headRow.Cells.Add(cornerCell);

            foreach (DataColumn col in tempdt.Columns)
            {
                string type = col.DataType.ToString();
                if (!(type.Contains(typeof(string).ToString()) || type.Contains(typeof(char).ToString())))
                {
                    names[h] = col.ColumnName.ToString();

                    TableCell cell = new TableCell();
                    cell.Text = names[h];
                    cell.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
                    cell.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
                    headRow.Cells.Add(cell);

                    h++;
                }
            }

            CorrTable.Rows.Add(headRow);

            for (int i = 0; i < correlMatrix.Rows(); i++)
            {
                double[] row = correlMatrix.GetRow(i);
                int length = row.Length;

                TableRow tR = new TableRow();

                TableCell rowName = new TableCell();
                rowName.Text = names[i];
                rowName.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
                rowName.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
                tR.Cells.Add(rowName);

                for (int j = 0; j < length; j++)
                {
                    TableCell cell = new TableCell();

                    if (j <= i)
                    {
                        cell.Text = row[j].ToString("0.###");
                    }
                    else
                    {
                        cell.Text = "-";
                    }

                    cell.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
                    cell.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
                    tR.Cells.Add(cell);
                }
                CorrTable.Rows.Add(tR);
            }
        }
開發者ID:logan-krall,項目名稱:HP-Project,代碼行數:85,代碼來源:Upload.aspx.cs

示例2: ToMatrixTest2

        public void ToMatrixTest2()
        {
            DataTable table = new DataTable("myData");
            table.Columns.Add("Double", typeof(double));
            table.Columns.Add("Integer", typeof(int));
            table.Columns.Add("Boolean", typeof(bool));

            table.Rows.Add(4.20, 42, true);
            table.Rows.Add(-3.14, -17, false);
            table.Rows.Add(21.00, 0, false);

            double[,] expected =
            {
                {  4.20,  42, 1 },
                { -3.14, -17, 0 },
                { 21.00,   0, 0 },
            };

            double[,] actual = table.ToMatrix();

            Assert.IsTrue(expected.IsEqual(actual));


            string[] expectedNames = { "Double", "Integer", "Boolean" };
            string[] actualNames;

            table.ToMatrix(out actualNames);

            Assert.IsTrue(expectedNames.IsEqual(actualNames));
        }
開發者ID:CanerPatir,項目名稱:framework,代碼行數:30,代碼來源:MatrixTest.cs

示例3: AnalysisData

        private ArrayDataView AnalysisData(DataTable dataTable)
        {
            DescriptiveAnalysis analysis;
            string[] columnNames;

            double[,] arrayData = dataTable.ToMatrix(out columnNames);

            // Analysis Data
            analysis = new DescriptiveAnalysis(arrayData, columnNames);
            analysis.Compute();

            double[,] analysisData = new double[0, arrayData.GetLength(1)];

            analysisData = analysisData.InsertRow<double>(analysis.Distinct.ToDouble(), analysisData.GetLength(0));
            analysisData = analysisData.InsertRow<double>(analysis.Means, analysisData.GetLength(0));
            analysisData = analysisData.InsertRow<double>(analysis.Medians, analysisData.GetLength(0));
            analysisData = analysisData.InsertRow<double>(analysis.Modes, analysisData.GetLength(0));
            analysisData = analysisData.InsertRow<double>(analysis.StandardDeviations, analysisData.GetLength(0));
            analysisData = analysisData.InsertRow<double>(analysis.Variances, analysisData.GetLength(0));
            analysisData = analysisData.InsertRow<double>(analysis.Sums, analysisData.GetLength(0));

            string[] rowNames = { "Distinct", "Means", "Medians", "Modes", "StandardDeviations", "Variances", "Sums" };

            return new ArrayDataView(analysisData, columnNames, rowNames);
        }
開發者ID:hpbaotho,項目名稱:benhvien,代碼行數:25,代碼來源:FormMainTabPreprocessingData.cs


注:本文中的System.Data.DataTable.ToMatrix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。