[Numpy-discussion] fancy view question

Vincent Schut schut at sarvision.nl
Tue Feb 17 05:04:08 EST 2009


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.




More information about the NumPy-Discussion mailing list