2 回答
TA贡献1876条经验 获得超7个赞
MathNet 限制是您只能使用Double、或数字类型来实现此目的Single。ComplexComplex32
using MathNet.Numerics.LinearAlgebra;
// ...
double[][] biglist = new double[3][];
biglist[0] = new double[] { 1, 2, 3, 4, 5 };
biglist[1] = new double[] { 5, 3, 3, 2, 1 };
biglist[2] = new double[] { 3, 4, 4, 5, 2 };
Matrix<double> matrix = Matrix<double>.Build.DenseOfColumns(biglist);
Console.WriteLine(matrix);
给出:
DenseMatrix 5x3-Double
1 5 3
2 3 4
3 3 4
4 2 5
5 1 2
TA贡献1850条经验 获得超11个赞
如果我很了解你,你正在尝试做这样的事情:
public static int[,] GetMatrix(IReadOnlyList<int[]> bigList)
{
if (bigList.Count == 0) throw new ArgumentException("Value cannot be an empty collection.", nameof(bigList));
var matrix = new int[bigList.Count, bigList[0].Length];
for (var bigListIndex = 0; bigListIndex < bigList.Count; bigListIndex++)
{
int[] list = bigList[bigListIndex];
for (var numberIndex = 0; numberIndex < list.Length; numberIndex++) matrix[bigListIndex, numberIndex] = list[numberIndex];
}
return matrix;
}
private static void Main(string[] args)
{
var biglist = new List<int[]>
{
new[] {1, 2, 3, 4, 5},
new[] {5, 3, 3, 2, 1},
new[] {3, 4, 4, 5, 2}
};
int[,] matrix = GetMatrix(biglist);
for (var i = 0; i < matrix.GetLength(1); i++)
{
for (var j = 0; j < matrix.GetLength(0); j++)
Console.Write($" {matrix[j, i]} ");
Console.WriteLine();
}
Console.ReadKey();
}
- 2 回答
- 0 关注
- 212 浏览
添加回答
举报