[Numpy-discussion] subsampling

Charles G Waldman cgw at alum.mit.edu
Thu Feb 14 18:43:01 CST 2002


Mathew Yeates writes:

 > how can I take a matrix and subsample it down to
 > an arbitrary size? It seems that using slices is
 > limited to constant integer step sizes while, if
 > I'm converting between arbitrary sizes, I would like
 > to subsample at a nonuniform rate.

I'm not sure exactly what you're trying to do, but maybe the following
Python session will show you the way.

>>> from Numeric import *
>>> take.__doc__   
'take(a, indices, axis=0).  Selects the elements in indices from array a along t   he given axis.'
>>> a = fromfunction(lambda i,j: 10*i+j, (10,5))
>>> a
array([[ 0,  1,  2,  3,  4],
       [10, 11, 12, 13, 14],
       [20, 21, 22, 23, 24],
       [30, 31, 32, 33, 34],
       [40, 41, 42, 43, 44],
       [50, 51, 52, 53, 54],
       [60, 61, 62, 63, 64],
       [70, 71, 72, 73, 74],
       [80, 81, 82, 83, 84],
       [90, 91, 92, 93, 94]])
>>> b = take(a,(0,2,3,5,7))
>>> b
array([[ 0,  1,  2,  3,  4],
       [20, 21, 22, 23, 24],
       [30, 31, 32, 33, 34],
       [50, 51, 52, 53, 54],
       [70, 71, 72, 73, 74]])
>>> c = take(b,(0,2,3), 1)
>>> c
array([[ 0,  2,  3],
       [20, 22, 23],
       [30, 32, 33],
       [50, 52, 53],
       [70, 72, 73]])




More information about the Numpy-discussion mailing list