本文整理匯總了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);
}
}
示例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));
}
示例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);
}