[Numpy-discussion] interleaving arrays
Emmanuelle Gouillart
emmanuelle.gouillart at normalesup.org
Sun Jun 14 10:21:43 EDT 2009
a = np.empty(3*n.size, np.int)
a[::3]=n
a[1::3]=m
a[2::3]=o
or
np.array(zip(n,m,o)).ravel()
but the first solution is faster, even if you have to write more :D
Emmanuelle
On Sun, Jun 14, 2009 at 04:11:29PM +0200, Robert wrote:
> whats the right way to efficiently weave arrays like this ? :
> >>> n
> array([1, 2, 3, 4])
> >>> m
> array([11, 22, 33, 44])
> >>> o
> array([111, 222, 333, 444])
> =>
> [ 1, 11, 111, 2, 22, 222, 3, 33, 333, 4, 44, 444]
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list