[Numpy-discussion] fancy view question

Stéfan van der Walt stefan at sun.ac.za
Tue Feb 17 09:31:41 EST 2009


Hi Vincent

2009/2/17 Vincent Schut <schut at sarvision.nl>:
> Hi list,
>
> would it be possible to create a view on an array, such that this view
> is twice as large (in some dimensions) and in fact does a nearest
> neighbour 'zoom' on the original array? E.g. using some fancy
> slicing/striding tricks?
>
> an example:
>
> a = [[1, 2],
>      [3, 4]]
>
> then I'd like a view on a such that this view is:
>
> [[1, 1, 2, 2],
>  [1, 1, 2, 2],
>  [3, 3, 4, 4],
>  [3, 3, 4, 4]]

np.lib.stride_tricks.as_strided(x, (2, 2, 2, 2), (8, 0, 4, 0)).reshape((4, 4))

Cheers
Stéfan



More information about the NumPy-Discussion mailing list