[Numpy-discussion] How to combine a pair of 1D arrays?
Wed Apr 14 12:20:08 CDT 2010
> On Wed, Apr 14, 2010 at 10:25, Peter Shinners <firstname.lastname@example.org>
>> 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.
You could start with the 2d array... instead of:
> >>> a = np.array((1,2,3,4))
> >>> b = np.array((11,12,13,14))
> >>> c = np.magical_fuse(a, b) # what goes here?
perhaps something like:
>>> c = np.empty((2,4), int)
>>> a = c
>>> b = c
Now a and b are views on c. So if you (say) pass them to, say, some
(strides-aware) C routine that fills them in element-by-element, c
will get filled in at the same time.
More information about the NumPy-Discussion