[SciPy-user] Question about trick index functions.

Hugo Gamboa hgamboa at gmail.com
Thu Jan 5 21:25:58 CST 2006


I got the idea, and since I'm still working my transition from matlab
I thought that the c_ for one dimension would do a row vector, for
those quick matrix build ups like:

>r_[1,2,3]+r_[1,2,3,'c']
matrix([[2, 3, 4],
       [3, 4, 5],
       [4, 5, 6]])



that is even better than in matlab via the broadcasting functionality.

I thought that for using that kind of broadcasting I could use a very
quick code like:

r_[1,2,3]+c_[1,2,3].

Thanks for the quick answers.

Hugo Gamboa


On 1/6/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
> Hugo Gamboa wrote:
>
> >So what is the difference between r_ and c_ ?
> >
> >
> >
> c_ is deprecated (it's there only for compatibility) :-)
>
> For 1-d arrays there was never any difference.
>
> For 2-d arrays c_ and r_ stacked along different dimensions.
>
> Now, the r_ constructor can stack along any dimension by using a string
> integer as the last element, but note this has the same limitation as
> concatenate:  the arrays stacked together must actually have the
> dimension to stack along....
>
> Compare the output of
>
> a = arange(6).reshape(2,3)
>
> r_[a,a]
>
> with
>
> r_[a,a,'-1']
>
> c_[a,a]  # not recommended for use anymore...
>
>
> The real use of r_[] is to quickly concatenate arrays together to build
> up complicated arrays.  It was developed when I was using SciPy to teach
> a signal processing course and the student lab-manuals had Matlab
> exercises where they used matlab to build up compilcated arrays quickly
> using bracket notation:
>
> -Travis
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>



More information about the SciPy-user mailing list