[SciPy-user] the meaning of c_ and r_

Robert Kern rkern at ucsd.edu
Thu Oct 21 19:24:50 CDT 2004


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?

transpose(a) only flips the order of the axes. For a rank-1 array, it 
just maps back to itself. Rank-1 arrays are neither strictly row-vectors 
or strictly column-vectors. If you want to ensure that they are row- or 
column-vectors, use the atleast_2d() function.

In [7]: a = r_[1:3:5j]

In [8]: a.shape
Out[8]: (5,)

In [9]: transpose(a).shape
Out[9]: (5,)

In [10]: c = atleast_2d(a)

In [11]: c.shape
Out[11]: (1, 5)

In [13]: transpose(c).shape
Out[13]: (5, 1)

In [14]: c
Out[14]: NumPy array, format: long
[ [ 1.   1.5  2.   2.5  3. ]]

In [15]: transpose(c)
Out[15]: NumPy array, format: long
[[ 1. ]
  [ 1.5]
  [ 2. ]
  [ 2.5]
  [ 3. ]]

> And: if I got some functions that might be useful to others, and want to
> contribute them, where do I turn to?

For batting around the issue on the mailing list, you can post them here 
if they are small, or preferably put them on a website and post the url 
here.

If you know where they ought to go in scipy, you can make a patch and 
submit it to the issue tracker. Assign the issue to me (rkern), and I'll 
make sure it gets dealt with.

http://www.scipy.net/roundup/scipy/index

> I got some interp2() function, modeled after (translated from) the octave 
> algorithm, and a polyfit() more or less woven from same wool...

That's a little murky license-wise. We want to keep everything 
BSD-licensed, and I assume that the original sources for these functions 
are GPLed.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the SciPy-user mailing list