# [Numpy-discussion] fancy view question

josef.pktd@gmai... josef.pktd@gmai...
Tue Feb 17 09:15:19 CST 2009

```On Tue, Feb 17, 2009 at 10:09 AM, Robert Kern <robert.kern@gmail.com> wrote:
> On Tue, Feb 17, 2009 at 08:44, Gael Varoquaux
> <gael.varoquaux@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 :).
>
> np.repeat(np.repeat(x, 2, axis=0), 2, axis=1)
>
> stride_tricks are fun, but this is already a solved problem in numpy.
>
> --
> Robert Kern
>

>>> b = np.repeat(np.repeat(a, 2, axis=0), 2, axis=1)
>>> b.flags
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : True
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False

Does OWNDATA : True  mean it made a copy? Or is there another way to
check whether it's a view or a copy?
zoom has OWNDATA : False

>>> c = zoom(a, 3,2)
>>> c.flags
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False

Josef
```