0

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.

nuclear sweet
  • 1,079
  • 10
  • 27
  • Thats not duplicate, read what i asking. Not parts of N size, but N parts with UNKNOWN size. – nuclear sweet Aug 23 '18 at 15:57
  • 1
    `itemsPerChunk` is your `N` size. – DavidG Aug 23 '18 at 15:59
  • Same thing isn't it? You know the size of the array you want to split and the number of arrays you want so based on that you calculate the estimated batch size and then apply the solutions suggested in the duplicate. – Igor Aug 23 '18 at 16:00
  • @Igor i need to have somehow equal parts of certain number, because the final goal after this split methods is find average value of each part. So instead of 5159 values, i need 790, like this was scaled or something. – nuclear sweet Aug 23 '18 at 16:00
  • ItemsPerChunk is wrong, as i said its 6 (integer), but i need 6.53 items per part actually (thats impossible for sure). – nuclear sweet Aug 23 '18 at 16:02
  • Maybe you can rephrase the question because I am not sure what you mean/want. At some point you will have an array from the split that does not have the same number of values as the other arrays (unless there is no remainder). – Igor Aug 23 '18 at 16:02
  • `preserving average values` <= that still does not make sense. Can you provide an [mcve] of what you expect or a very basic input with expected output? – Igor Aug 23 '18 at 16:06
  • 1
    How can you possibly have 6.53 items? This makes no sense. As Igor says, please provide the exact input and output that you are expecting. – DavidG Aug 23 '18 at 16:16
  • @DavidG probably i need some kind of interpolation or something.. Reduce frequency of discretization – nuclear sweet Aug 23 '18 at 17:17
  • Sounds more like you want to create a moving average chart, but there are many ways of mathematically doing this. You need to figure out which method you need. – DavidG Aug 24 '18 at 13:17

0 Answers0