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

Sturla Molden sturla at molden.no
Wed Sep 2 11:11:35 EDT 2009


V. Armando Solé skrev:
> I am looking for a way to have a non contiguous array C in which the 
> "left" (10000, 2000) elements point to A and the "right" (10000, 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((10000, 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



More information about the NumPy-Discussion mailing list