# [Numpy-discussion] r_, c_, hstack, and vstack with 1-d arrays

Bill Baxter wbaxter at gmail.com
Wed Jul 19 07:28:24 CDT 2006

```For 1-d inputs I think r_ should act like vstack, and c_ should act
like column_stack.
Currently r_ and c_ both act like hstack for 1-d inputs.

Background:
I keep getting bitten by the fact that this doesn't work:

>>> a = array([1,2,3])
>>> b = array([[1,2,3],[2,3,4]])
>>> c = array([4,5,6])
>>> r_[b,c]
**error**

and that this doesn't return a 2x3
>>> d = r_[a,c]
array([1, 2, 3, 4, 5, 6])

To get what I want I need something like :
>>> r_[[a],[c]]
array([[1, 2, 3],
[4, 5, 6]])
And to get them columnwise I need the likes of:
>>> c_[a[:,newaxis], c[:,newaxis]]
array([[1, 4],
[2, 5],
[3, 6]])

It seems like the r_ (which I think of as a "row concatenator") should
assume that 1-d arrays are rows (like vstack does), and the c_
("column concatenator") should assume 1-d arrays are columns (like
column_stack does).

Then you'd have:
>>> r_[a,c]
array([[1, 2, 3],
[4, 5, 6]])
>>> c_[a,c]
array([[1, 4],
[2, 5],
[3, 6]])

At any rate, r_'s behavior is currently different from vstack wrt 1-d
arrays, and identitcal to c_ and hstack.

Vstack, hstack, and column_stack give the following:
>>> vstack([a,c])
array([[1, 2, 3],
[4, 5, 6]])
>>> hstack([a,c])
array([1, 2, 3, 4, 5, 6])
>>> column_stack([a,c])
array([[1, 4],
[2, 5],
[3, 6]])

Also isn't it odd that there's a column_stack, but no row_stack?  I
guess that's because row_stack would just be an alias for vstack, but
still.

--bb

```