How to reduce the size of NumPy 1dim array

We often have to deal with very long lists of element, like audio data, and sometimes we want to reduce size to increase processing speed. There are many functions for image but not for 1dim array. I propose you my solution using only NumPy function.

Here is my solution !

def resize(inputArray, newLength):
block_size = len(inputArray)//newLength
outputArray = inputArray[0:block_size*newLength].reshape((block_size, newLength))
outputArray = np.mean(outputArray, axis=0)//np.max/np.min...
outputArray = outputArray.reshape((newLength))
return outputArray

We reshape the array into a 2dims array constituted of block we will represent by one element using Mean, Max, Min or any function you want to use to reduce size of your array.

Note: this method only works to reduce size and cannot be used to increase the size of the array.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store