C#: Any faster way of copying arrays?
Posted
by
Yang
on Stack Overflow
See other posts from Stack Overflow
or by Yang
Published on 2011-02-24T02:06:48Z
Indexed on
2011/02/24
7:24 UTC
Read the original article
Hit count: 183
I have three arrays that need to be combined in one three-dimension array. The following code shows slow performance in Performance Explorer. Is there a faster solution?
for (int i = 0; i < sortedIndex.Length; i++) {
if (i < num_in_left)
{
// add instance to the left child
leftnode[i, 0] = sortedIndex[i];
leftnode[i, 1] = sortedInstances[i];
leftnode[i, 2] = sortedLabels[i];
}
else
{
// add instance to the right child
rightnode[i-num_in_left, 0] = sortedIndex[i];
rightnode[i-num_in_left, 1] = sortedInstances[i];
rightnode[i-num_in_left, 2] = sortedLabels[i];
}
}
Update:
I'm actually trying to do the following:
//given three 1d arrays
double[] sortedIndex, sortedInstances, sortedLabels;
// copy them over to a 3d array (forget about the rightnode for now)
double[] leftnode = new double[sortedIndex.Length, 3];
// some magic happens here so that
leftnode = {sortedIndex, sortedInstances, sortedLabels};
© Stack Overflow or respective owner