If downsampling implies something like this , you can just slice the array. For example 1D:
import numpy as np
a = np.arange(1,11,1)
print(a)
print(a[::3])
The last line is equivalent:
print(a[0:a.size:3])
with the designation of slicing as start:stop:step
Result:
[1 2 3 4 5 6 7 8 9 10]
[1 4 7 10]
For a two-dimensional array, the idea is the same:
b = np.arange(0,100)
c = b.reshape([10,10])
print(c[::3,::3])
This gives you, in both dimensions, every third element from the original array.
Or, if you just want to select a sample of one dimension:
d = np.zeros((400,250))
print(d.shape)
e = d[::10,:]
print(e.shape)
(400, 250)
(40, 250)
There are many other examples in the Numpy manual.
source
share