As example, i have array with size 5159. I need to scale it into 790 values, but keep them on same level. As example with smaller size: if i have [4, 4, 4, 1, 3, 5] array and scale it to array of 2 elements it will be [4 ,3] - first three average value is 4, second three became 4. But if i have array [4, 4, 4, 3, 2] i have no idea how to scale it into 2 values. Because each part need average from 2.5 elements.
I tried like:
private static IEnumerable<List<byte>> SplitList(List<byte> samples, int chunks)
{
var list = new List<List<byte>>();
var itemsPerChunk = samples.Count / chunks;
for (int i = 0; i < samples.Count; i += itemsPerChunk)
{
list.Add(samples.GetRange(i, Math.Min(itemsPerChunk, samples.Count - i)));
}
return list;
}
But that not works, and returns 860 parts, because itemsPerChunk
is integer (6 instead of actual 6.53.. ). Any suggestions?
edit: To make it more clear, final goal is to scale this 5159 array into 790 array, preserving average values.
To make it more clear: i have alot of values for drawning chart, how much is unknown until program runs. I need to make array of smaller amount of values, but with same "shape" as original array.