我有N个多维源数据数组,每个数组都有相同数量的列(在此示例中为C=4),但行数可以是任意数量:
var array1 = new double[,]
{
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 }
};
var array2 = new double[,]
{
{ 1, 2, 5, 6 },
{ 7, 8, 9, 10 },
{ 9, 10, 11, 12 }
};
var array3 = new double[,]
{
{ 1, 2, 7, 8 },
{ 13, 14, 15, 16 }
};
...
var arrayN = new double[,] { ... };
我还有一个数组,指定在源数组中哪些索引将用作连接键:
var keyArray = new int[] { 0, 1 };
我需要将数组连接起来,使得结果数组看起来像这样:
var result = new double[,]
{
// The length of each element in this array will be (C x N),
// the first C elements will be from array1, the next C from
// array2, and so on, and nulls used for arrays elements that
// are not included in the join (keys don't match).
//
// The number of rows in this array will be the number of distinct key combinations.
{ 1, 2, 3, 4, 1, 2, 5, 6, 1, 2, 7, 8 },
{ 5, 6, 7, 8, null, null, null, null, null, null, null, null },
{ 9, 10, 11, 12, 9, 10, 11, 12, null, null, null, null },
{ null, null, null, null, 7, 8, 9, 10, null, null, null, null },
{ null, null, null, null, null, null, null, null, 13, 14, 15, 16 }
};
我认为我需要从每个源数组中选择不同的键,并循环遍历所有数据并比较每一行等,以填充结果数组。然而,使用LINQ应该有更有效的方法来完成这个任务 - 有人可以帮忙吗?