[SciPy-user] the meaning of c_ and r_
Gerald Richter
richter at hephy.oeaw.ac.at
Mon Oct 25 09:02:44 CDT 2004
I find the idea to introduce something like row_ and col_ very
convenient. Given that it does:
row_[1:4:4j]
= array[ [ 1, 2, 3, 4 ] ]
col_[1:4:4j]
= array[ [ 1 ],
[ 2 ],
[ 3 ],
[ 4 ] ]
also, it seems reasonable, to provide something that does convert any 1-d
object to the desired columns or row-shape
a = ( 1,2,3)
row(a)
= array[ [ 1, 2, 3 ] ]
... similar for col()
+++
I played arround a little with the functionality of c_ and r_ to understand
it better... maybe these are examples to add to the documentation, so that
it becomes more clear what these functions do?
a = array([c_[1:4:4j]])
[ [ 1. 2. 3. 4.]]
at = transpose(a)
[[ 1.]
[ 2.]
[ 3.]
[ 4.]]
b = array([c_[5:8:4j]])
[ [ 5. 6. 7. 8.]]
bt = transpose(b)
[[ 5.]
[ 6.]
[ 7.]
[ 8.]]
c_[a,b]
[ [ 1. 2. 3. 4. 5. 6. 7. 8.]]
c_[at,bt]
[[ 1. 5.]
[ 2. 6.]
[ 3. 7.]
[ 4. 8.]]
r_[a,b]
[[ 1. 2. 3. 4.]
[ 5. 6. 7. 8.]]
r_[at,bt]
[[ 1.]
[ 2.]
[ 3.]
[ 4.]
[ 5.]
[ 6.]
[ 7.]
[ 8.]]
greetings,
Gerald
On Fri, Oct 22, 2004 at 02:07:53PM -0600, Travis Oliphant wrote:
> 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
>
>
>
> _______________________________________________
> 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