[Numpy-discussion] How to combine a pair of 1D arrays?

Robert Kern robert.kern@gmail....
Wed Apr 14 10:34:18 CDT 2010

On Wed, Apr 14, 2010 at 10:25, Peter Shinners <pete@shinners.org> wrote:
> Is there a way to combine two 1D arrays with the same size into a 2D
> array? It seems like the internal pointers and strides could be
> combined. My primary goal is to not make any copies of the data.

There is absolutely no way to get around that, I am afraid.

> It
> might be doable with a bit of ctypes if there is not a native numpy call.
>  >>> import numpy as np
>  >>> a = np.array((1,2,3,4))
>  >>> b = np.array((11,12,13,14))
>  >>> c = np.magical_fuse(a, b)   # what goes here?

c = np.vstack([a, b])

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the NumPy-Discussion mailing list