[Numpy-discussion] avoiding loops when downsampling arrays

Sturla Molden sturla at molden.no
Mon Feb 6 16:27:36 EST 2012



> 
> # Make a 4D view of this data, such that b[i,j]
> # is a 2D block with shape (4,4) (e.g. b[0,0] is
> # the same as a[:4, :4]).
> b = as_strided(a, shape=(a.shape[0]/4, a.shape[1]/4, 4, 4),
>                strides=(4*a.strides[0], 4*a.strides[1], a.strides[0], a.strides[1]))
> 

Yes :-) Being used to Fortran (and also MATLAB) this is the kind of mapping It never occurs for me to think about. What else but NumPy is flexible enough to do this? :-)

Sturla


More information about the NumPy-Discussion mailing list