# [PYTHON MATRIX-SIG] [tbyang@icf.llnl.gov: Some subtlety in
reaching items of a matrix]

**James Hugunin
**
jjh@mama-bear.lcs.mit.edu

*Fri, 10 Nov 95 12:08:37 -0500*

>* For a rank-3 matrix `c', there are some subtle difference between
*>* C[0][1] and c[(0,1)]. The following example illustrates this:
*
<snip>
First, I agree completely, this is terrible. Nevertheless, here's my
justification:
Returning a matrix by-copy is always the best thing to do conceptually (I
guess I've played with too many functional languages). I find it a lot
easier to think about my matrix code if I don't have to worry about
references to objects.
On the other hand, if you want to allow python indexing of the style
a[i][j] to function with any sort of reasonable efficiency, then you need to
have a[i] return by reference.
I'm perfectly willing to be convinced to change over to always returning
matrices by reference (with the understanding that the code will have many
more bugs, and the understanding that if a = Matrix(1,2,3) then a[0] will
return not a python float, but a 0d matrix with the same sort of reference
style semantics) or to always returning arrays by copy with the
understanding that a[i][j] will potentially be an incredibly inefficient way
of accessing an array element.
I'm not happy with my chosen compromise. I just can't come up with a
better solution.
-Jim
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================