[SciPy-user] the meaning of c_ and r_
Francesc Alted
falted at pytables.org
Fri Oct 22 08:19:19 EDT 2004
A Divendres 22 Octubre 2004 01:53, Gerald Richter va escriure:
> shouldn't c_[...] result in something like
> array([ [ . ],
> [ . ] ])
> while r_ results in
> array([ ... ])
> ?
>
> why does:
>
> In [23]: a = r_[1:3:5j]
>
> In [24]: b = c_[2:6:5j]
>
In SciPy tutorial (http://www.scipy.org/documentation/tutorial.pdf) Travis
Oliphant says:
"""
The "r" stands for row concatenation because if the ob jects between commas
are 2 dimensional arrays, they are stacked by rows (and thus must have
commensurate columns). There is an equivalent command c that stacks 2d
arrays by columns but works identically to r for 1d arrays.
"""
So, it seems that this is not a bug, but a feature. Although I would also
find interesting that r_[1:3:5j] would generate:
array([ 1. , 1.5, 2. , 2.5, 3. ])
and that c_[1:3:5j]) would do:
array([[ 1. ],
[ 1.5],
[ 2. ],
[ 2.5],
[ 3. ]])
However, I don't know if this would be counter-intuitive in some cases.
--
Francesc Alted
More information about the SciPy-User
mailing list