Reputation: 1665
Im relatively new to numpy but have started using it to read and write from and to h5 files. I have image data on which I have computed some zonal statistics, reading each pixel value in a given zone into a h5 file. However, I have a lot of pixel values (possibly tens of millions) and wanted to subsample this data so that I am able to cut down the data size but keep the general distribution of the data.
I was wondering if there was a simple way of sampling every 200th value of an array?
I would put up what code I have already but my code only goes as far as to read in my existing data - Im completely stuck as to how I might subsample it so have nothing to show so far.
Thanks
Upvotes: 1
Views: 5679
Reputation: 362488
You can use an array slice:
>>> import numpy as np
>>> a = np.eye(1000)
>>> a[::200, ::200]
array([[ 1., 0., 0., 0., 0.],
[ 0., 1., 0., 0., 0.],
[ 0., 0., 1., 0., 0.],
[ 0., 0., 0., 1., 0.],
[ 0., 0., 0., 0., 1.]])
Upvotes: 8