# [SciPy-user] the meaning of c_ and r_

Travis Oliphant oliphant at ee.byu.edu
Fri Oct 22 15:07:53 CDT 2004

```Robert Kern wrote:

> Gerald Richter wrote:
>
>> Hi everybody.
>>
>> Sorry for such a basic question, or maybe two:
>>
>> shouldn't c_[...] result in something like
>> array([ [ . ],
>>         [ . ] ])
>> while r_ results in array([ ... ])
>> ?
>
>
> Probably. Travis will probably have to step in here and explain what
> they are supposed to do in this case.
>

>> why does:
>>
>> In [23]: a = r_[1:3:5j]
>>
>> In [24]: b = c_[2:6:5j]
>>
>> In [25]: b
>> Out[25]: array([ 2.,  3.,  4.,  5.,  6.])
>>
>> In [26]: a
>> Out[26]: array([ 1. ,  1.5,  2. ,  2.5,  3. ])
>>
>> In [27]: transpose a
>> -------> transpose(a)
>> Out[27]: array([ 1. ,  1.5,  2. ,  2.5,  3. ])
>>
>> In [28]: transpose b
>> -------> transpose(b)
>> Out[28]: array([ 2.,  3.,  4.,  5.,  6.])
>>
>> not allow transposition in the above mentioned way?
>
>
SciPy is early enough in it's development that the behavior of r_ and c_
could be changed without extensive grief at this point, if it was
important to change them.

The idea of r_  was to allow fast creation of arrays similar to what is
available with MATLAB.  I wanted a short, quick way to concatenate and
generate arrays.  For 1-d arrays, r_ and c_ are supposed to be exactly
the same.  It's only when you give them two dimensional arrays that they
differ.  Admittedly, I really like the one-dimensional array creation
ability of r_  and I use it quite often.  The two-dimensional array
creation is not as good.  bmat is intended to improve that some.    I am
open to any ideas about how to improve this.  Perhaps, we just kill c_
and suggest something else (like an improved bmat) for building 2-d
arrays quickly.

But, your transpose question is resolved by recognizing that there is a
difference between a rank-1 array and a rank-2 matrix (which can be a
column or row).  Perhaps we should have a mechanism (perhaps a
row_[...])  that generates a rank-2 row vector very quickly.

Ideas are welcome,

-Travis

```