4

Let's say I have two arrays a and b.

a.shape is (95, 300)
b.shape is (95, 3)

How can I obtain a new array c by concatenating each of the 95 lines ?

c.shape is (95, 303)
C.B.
  • 8,096
  • 5
  • 20
  • 34
valentin
  • 1,103
  • 2
  • 16
  • 36
  • 1
    which datatype(s)/libraries are you suing? are they tuples? are they dt from a gis library? what are the rules for combining the data structures? – dm03514 Apr 09 '14 at 16:28
  • Take a look are the following: http://stackoverflow.com/questions/1720421/merge-two-lists-in-python – morissette Apr 09 '14 at 16:29

1 Answers1

3

IIUC, you could use hstack:

>>> a = np.ones((95, 300))
>>> b = np.ones((95, 3)) * 2
>>> a.shape
(95, 300)
>>> b.shape
(95, 3)
>>> c = np.hstack((a,b))
>>> c
array([[ 1.,  1.,  1., ...,  2.,  2.,  2.],
       [ 1.,  1.,  1., ...,  2.,  2.,  2.],
       [ 1.,  1.,  1., ...,  2.,  2.,  2.],
       ..., 
       [ 1.,  1.,  1., ...,  2.,  2.,  2.],
       [ 1.,  1.,  1., ...,  2.,  2.,  2.],
       [ 1.,  1.,  1., ...,  2.,  2.,  2.]])
>>> c.shape
(95, 303)
DSM
  • 342,061
  • 65
  • 592
  • 494