Home > Blockchain >  How to scale down a list of integers
How to scale down a list of integers

Time:11-07

I have a list, that can be of various lengths (less than 100 or more than 1.800.000) and I need to display all those values on a graph (a waveform) of 800 points on which I can draw.

I have tried taking a value for every step, where a step is the list length / 800. And it is the closest I can get to. I have tried taking the average value of the n surrounding of step with various n, but I can't get a waveform that satisfies me.

I know image compression work by taking an average of surrounding pixels, and I am trying to do the same with a list of values going from 0 to 200. I need to preserve the global aspect, but also the highest and lowest spikes.

CodePudding user response:

First of all this is more resampling than scaling. As mentioned in the comments you have 2 cases:

  1. upscaling/sampling n<800

    this is relatively simple you just interpolate the missing values. I would go for before after Python code :

    numberOfSmallerList = 400
    small_list_len = int(len(big_list) / numberOfSmallerList)
    
    finalPointsToPlot = []
    
    for i in range(0, len(big_list), small_list_len):
        biggestDiff = max(big_list[i:i small_list_len]) - 
        min(big_list[i:i small_list_len])
    
        finalPointsToPlot.append(biggestDiff/2   100)
        finalPointsToPlot.append(100 - biggestDiff/2)
    
    
    import matplotlib.pyplot as plt
    plt.plot(finalPointsToPlot)
    plt.show()
    
  • Related