[Numpy-discussion] fancy view question

josef.pktd at gmail.com josef.pktd at gmail.com
Tue Feb 17 10:01:21 EST 2009


On Tue, Feb 17, 2009 at 9:44 AM, Gael Varoquaux
<gael.varoquaux at normalesup.org> wrote:
> On Tue, Feb 17, 2009 at 04:42:21PM +0200, Stéfan van der Walt wrote:
>> Or, more generally:
>
>> import numpy as np
>
>> def zoom(x, factor=2):
>>         rows, cols = x.shape
>>         row_stride, col_stride = x.strides
>>         view = np.lib.stride_tricks.as_strided(x,
>>                         (rows, factor, cols, factor),
>>                         (row_stride, 0, col_stride, 0))
>>         return view.reshape((rows*factor, cols*factor))
>
> That's handy, you should commit this somewhere. Actually, it would be
> even cooler if you could have different zoom factor in different
> direction :).
>

I completely agree.

I was looking at the help file and docs, and I didn't find it.
np.lib.stride_tricks.as_strided is not in np.lib.stride_tricks.__all__
 and not in the docs. So it's still a hidden treasure.

Josef



More information about the NumPy-Discussion mailing list