Re: [Numpy-discussion] fancy view question

2009-02-18 Thread Vincent Schut
Gael Varoquaux wrote: > On Tue, Feb 17, 2009 at 10:18:11AM -0600, Robert Kern wrote: >> On Tue, Feb 17, 2009 at 10:16, Gael Varoquaux >> wrote: >>> On Tue, Feb 17, 2009 at 09:09:38AM -0600, Robert Kern wrote: np.repeat(np.repeat(x, 2, axis=0), 2, axis=1) > stride_tricks are fun, but thi

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Gael Varoquaux
On Tue, Feb 17, 2009 at 09:09:38AM -0600, Robert Kern wrote: > np.repeat(np.repeat(x, 2, axis=0), 2, axis=1) > stride_tricks are fun, but this is already a solved problem in numpy. Wow. I still have a lot to learn! How about adding a see-also in as_strided. Gaël _

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Gael Varoquaux
On Tue, Feb 17, 2009 at 10:18:11AM -0600, Robert Kern wrote: > On Tue, Feb 17, 2009 at 10:16, Gael Varoquaux > wrote: > > On Tue, Feb 17, 2009 at 09:09:38AM -0600, Robert Kern wrote: > >> np.repeat(np.repeat(x, 2, axis=0), 2, axis=1) > >> stride_tricks are fun, but this is already a solved proble

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Robert Kern
On Tue, Feb 17, 2009 at 10:16, Gael Varoquaux wrote: > On Tue, Feb 17, 2009 at 09:09:38AM -0600, Robert Kern wrote: >> np.repeat(np.repeat(x, 2, axis=0), 2, axis=1) > >> stride_tricks are fun, but this is already a solved problem in numpy. > > Wow. I still have a lot to learn! How about adding a s

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Stéfan van der Walt
2009/2/17 Robert Kern : >> To get back to the fun part: I see now the zoomed view is not a view >> but a new array. How do we get around that? > > You can't. numpy's memory model simply cannot represent that permutation. Right, something like the PIL's pointer-to-pointers format. I should have

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Robert Kern
On Tue, Feb 17, 2009 at 09:21, Stéfan van der Walt wrote: > 2009/2/17 Robert Kern : >> stride_tricks are fun, but this is already a solved problem in numpy. > > To get back to the fun part: I see now the zoomed view is not a view > but a new array. How do we get around that? You can't. numpy's

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Stéfan van der Walt
2009/2/17 Robert Kern : > stride_tricks are fun, but this is already a solved problem in numpy. To get back to the fun part: I see now the zoomed view is not a view but a new array. How do we get around that? Cheers Stéfan ___ Numpy-discussion mailing

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Robert Kern
On Tue, Feb 17, 2009 at 09:15, wrote: > I'm still learning about views: > 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 me

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Pauli Virtanen
Tue, 17 Feb 2009 10:15:19 -0500, josef.pktd wrote: [clip] > I'm still learning about views: [clip: c = foo(a); c.flags.owndata] > Does OWNDATA : True mean it made a copy? Yes. But owndata==False does not mean no copy was made (since the result could be a view to a temporary array). > Or is the

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread josef . pktd
On Tue, Feb 17, 2009 at 10:09 AM, Robert Kern wrote: > On Tue, Feb 17, 2009 at 08:44, Gael Varoquaux > 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 >>

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Robert Kern
On Tue, Feb 17, 2009 at 08:44, Gael Varoquaux 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.

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread josef . pktd
On Tue, Feb 17, 2009 at 10:01 AM, Gael Varoquaux wrote: > On Tue, Feb 17, 2009 at 04:58:57PM +0200, Stéfan van der Walt wrote: >> 2009/2/17 Gael Varoquaux : >> > That's handy, you should commit this somewhere. Actually, it would be >> > even cooler if you could have different zoom factor in differ

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread josef . pktd
On Tue, Feb 17, 2009 at 9:44 AM, Gael Varoquaux 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 = n

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Gael Varoquaux
On Tue, Feb 17, 2009 at 04:58:57PM +0200, Stéfan van der Walt wrote: > 2009/2/17 Gael Varoquaux : > > That's handy, you should commit this somewhere. Actually, it would be > > even cooler if you could have different zoom factor in different > > direction :). > Something like this: > a = np.array(

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Stéfan van der Walt
2009/2/17 Gael Varoquaux : > That's handy, you should commit this somewhere. Actually, it would be > even cooler if you could have different zoom factor in different > direction :). Something like this: a = np.array([[1, 2, 3], [4, 5, 6]]) print a print zoom(a, x=2, y=3) [[1 2 3]

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Gael Varoquaux
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,

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Stéfan van der Walt
2009/2/17 Stéfan van der Walt : > 2009/2/17 Vincent Schut : >> 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/strid

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread Stéfan van der Walt
Hi Vincent 2009/2/17 Vincent Schut : > 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:

Re: [Numpy-discussion] fancy view question

2009-02-17 Thread josef . pktd
On Tue, Feb 17, 2009 at 5:04 AM, Vincent Schut 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?

[Numpy-discussion] fancy view question

2009-02-17 Thread Vincent Schut
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