[Numpy-discussion] fancy view question

josef.pktd@gmai... josef.pktd@gmai...
Tue Feb 17 08:13:42 CST 2009


On Tue, Feb 17, 2009 at 5:04 AM, Vincent Schut <schut@sarvision.nl> wrote:
> 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]]
>
> I know several ways to create this as a copy, but as memory does play a
> role in this case (yes, I know it's cheap :-))...
>
> If not, fancy ways to create this as a copy are apreciated. I currently
> either create an empty array and then loop-fill it (e.g. this would be
> 2x2 loops), of if I' lazy I use ndimage.zoom, which actually is a bit
> overkill.
>
> Regards,
> Vincent.


I don't know about the view but your array just looks like a kronecker
product to me.

>>> import numpy as np
>>> np.kron([[1, 2], [3, 4]], [[1, 1], [1, 1]])
array([[1, 1, 2, 2],
       [1, 1, 2, 2],
       [3, 3, 4, 4],
       [3, 3, 4, 4]])

Josef


More information about the Numpy-discussion mailing list