[Tutor] Python 3 Combine 1 D Arrays

Peter Otten __peter__ at web.de
Thu May 18 03:07:22 EDT 2017


Stephen P. Molnar wrote:

> I'm beginning to think that I don't know how to ask the question as
> Google and Stack Overflow have resulted in nothing.  All of the results
> seem to deal with integers.
> 
> I have a number of single column floating point arrays each containing
> 300 entries that I want to combine into a n by 300 array where n is the
> number of single column arrays.
> 
> I have tried zip, np.concatenate etc with only failure.
> 
> Thanks in advance.
> 

Googling for

numpy combine 1d arrays into 2d array

I get

http://stackoverflow.com/questions/21322564/numpy-list-of-1d-arrays-to-2d-array

as the first hit. Does that help? The second hit

http://stackoverflow.com/questions/17710672/create-2-dimensional-array-with-2-one-dimensional-array

should also work, and the best approach is probably #3:

https://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.column_stack.html

>>> import numpy as np
>>> a = np.array([1.2, 3.4, 5.6])
>>> b = np.array([10.11, 12.13, 14.15])
>>> np.column_stack((a, b))
array([[  1.2 ,  10.11],
       [  3.4 ,  12.13],
       [  5.6 ,  14.15]])

No rocket science ;)



More information about the Tutor mailing list