从列表与LT转换;双层[]&GT;加倍[,] [英] Convert from List<double[]> to double[,]
本文介绍了从列表与LT转换;双层[]&GT;加倍[,]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个单行(无循环)的转换列表&LT;双层[]&GT;
到双击[,]
?
Is there an one-liner (no looping) that converts List<double[]>
to double[,]
?
推荐答案
转换为双击[,]
只能通过列表和循环来完成要求所有的数组列表中包含的是同样大小的
Converting to double[,]
can only be done by looping through the list and requires that all arrays contained in the list are of same size:
double[,] arr = new double[list.Count, list[0].Length];
for (int i = 0; i < list.Count; i++)
{
for (int j = 0; j < list[0].Length; j++)
{
arr[i, j] = list[i][j];
}
}
当然,你可以轻松地创建一个锯齿双击[] []
阵列阵列通过调用 .ToArray()
:
double[] array = new double[] { 1.0, 2.0, 3.0 };
double[] array1 = new double[] { 4.0, 5.0, 6.0 };
List<double[]> list = new List<double[]>();
list.Add(array);
list.Add(array1);
double[][] jaggedArray = list.ToArray();
这篇关于从列表与LT转换;双层[]&GT;加倍[,]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文