Re: [Numpy-discussion] How to concatenate two arrays without duplicating memory?

2009-09-02 Thread Sturla Molden
V. Armando Solé skrev:
> I am looking for a way to have a non contiguous array C in which the 
> "left" (1, 2000) elements point to A and the "right" (1, 4000) 
> elements point to B. 
>
> Any hint will be appreciated.

If you know in advance that A and B are going to be duplicated, you can 
use views:

C = np.zeros((1, 6000))
A = C[:,:2000]
B = C[:,2000:]

Now C is A and B concatenated horizontally.

If you can't to this, you could write the data to a temporary file and 
read it back, but it would be slow.

Sturla
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] How to concatenate two arrays without duplicating memory?

2009-09-02 Thread V. Armando Solé
Gael Varoquaux wrote:
> You cannot in the numpy memory model. The numpy memory model defines an
> array as something that has regular strides to jump from an element to
> the next one.
>   
I expected problems in the suggested case (concatenating columns) but I 
did not expect the problem would be so severe to affect the case of row 
concatenation.

I guess I am still considering a 2D array as an array of pointers and 
that does not apply to numpy arrays.

Thanks for the info.

Armando

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] How to concatenate two arrays without duplicating memory?

2009-09-02 Thread Gael Varoquaux
On Wed, Sep 02, 2009 at 09:40:49AM +0200, "V. Armando Solé" wrote:
> Let's say we have two arrays A and B of shapes (1, 2000) and (1, 
> 4000).

> If I do C=numpy.concatenate((A, B), axis=1), I get a new array of 
> dimension (1, 6000) with duplication of memory.

> I am looking for a way to have a non contiguous array C in which the 
> "left" (1, 2000) elements point to A and the "right" (1, 4000) 
> elements point to B. 

You cannot in the numpy memory model. The numpy memory model defines an
array as something that has regular strides to jump from an element to
the next one.

Gaël
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion