Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Alan G Isaac
On Tue, 27 Mar 2007, Zachary Pincus apparently wrote: Now, Bill offers up a different suggestion: indexing M yields neither a matrix nor an array, but a class that operates more or less like an array, except insofar as it interacts with other matrix objects, or other objects of similar

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Bill Spotz
What I envisioned was that M[i,:] would return a row_vector and M [:,j] would return a column_vector, because this would be symmetric behavior. M[i], by convention, would behave the same as M[i,:]. But then I personally don't distinguish between python indexing and numpy indexing. In both

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Charles R Harris
On 3/29/07, Bill Spotz [EMAIL PROTECTED] wrote: What I envisioned was that M[i,:] would return a row_vector and M [:,j] would return a column_vector, because this would be symmetric behavior. M[i], by convention, would behave the same as M[i,:]. But then I personally don't distinguish between

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Bill Spotz
On Mar 29, 2007, at 6:48 PM, Alan G Isaac wrote: On Thu, 29 Mar 2007, Bill Spotz apparently wrote: What I envisioned was that M[i,:] would return a row_vector and M[:,j] would return a column_vector, because this would be symmetric behavior. M[i], by convention, would behave the same as

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Timothy Hochberg
matrix.py The discussion about matrix indexing has been interminible and for the most part pretty pointless IMO. However, it does point out one thing: the interaction between the matrix and array classes is still pretty klunky despite a fair amount of effort trying to make them interoperate.

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Bill Baxter
On 3/30/07, Timothy Hochberg [EMAIL PROTECTED] wrote: Note, however that you can't (for instance) multiply column vector with a row vector: (c)(r) Traceback (most recent call last): ... TypeError: Cannot matrix multiply columns with anything That should be allowed. (N,1)*(1,M) is just

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Timothy Hochberg
On 3/29/07, Bill Baxter [EMAIL PROTECTED] wrote: On 3/30/07, Timothy Hochberg [EMAIL PROTECTED] wrote: Note, however that you can't (for instance) multiply column vector with a row vector: (c)(r) Traceback (most recent call last): ... TypeError: Cannot matrix multiply columns with

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Timothy Hochberg
On 3/29/07, Timothy Hochberg [EMAIL PROTECTED] wrote: On 3/29/07, Bill Baxter [EMAIL PROTECTED] wrote: On 3/30/07, Timothy Hochberg [EMAIL PROTECTED] wrote: Note, however that you can't (for instance) multiply column vector with a row vector: (c)(r) Traceback (most recent call

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Charles R Harris
On 3/29/07, Timothy Hochberg [EMAIL PROTECTED] wrote: On 3/29/07, Bill Baxter [EMAIL PROTECTED] wrote: On 3/30/07, Timothy Hochberg [EMAIL PROTECTED] wrote: Note, however that you can't (for instance) multiply column vector with a row vector: (c)(r) Traceback (most recent call

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Zachary Pincus
Looks promising! On 3/29/07, Bill Baxter [EMAIL PROTECTED] wrote: On 3/30/07, Timothy Hochberg [EMAIL PROTECTED] wrote: Note, however that you can't (for instance) multiply column vector with a row vector: (c)(r) Traceback (most recent call last): ... TypeError: Cannot

Re: [Numpy-discussion] matrix indexing question

2007-03-29 Thread Bill Baxter
On 3/30/07, Timothy Hochberg [EMAIL PROTECTED] wrote: On 3/29/07, Bill Baxter [EMAIL PROTECTED] wrote: On 3/30/07, Timothy Hochberg [EMAIL PROTECTED] wrote: Note, however that you can't (for instance) multiply column vector with a row vector: (c)(r) Traceback (most recent call

Re: [Numpy-discussion] matrix indexing question

2007-03-28 Thread Robert Kern
Alan G Isaac wrote: On Tue, 27 Mar 2007, Robert Kern apparently wrote: Gram-Schmidt orthogonalization Alan G Isaac wrote: I take it from context that you consider it desirable to end up with a list of matrices? Robert wrote: Honestly, I don't care. You asked about iteration, and

Re: [Numpy-discussion] matrix indexing question

2007-03-28 Thread Alan Isaac
On Tue, 27 Mar 2007, Zachary Pincus wrote: M[i], which equals M[i,:] Of course this equality must break. That was stated at the outset. As I said before, this may be impossible or undesirable. But, as I said before, it seems prima facie natural for M[i] to be ordinary Python indexing while

Re: [Numpy-discussion] matrix indexing question (final post)

2007-03-28 Thread Stefan van der Walt
On Wed, Mar 28, 2007 at 07:05:00PM -0500, Alan Isaac wrote: On Wed, 28 Mar 2007, Stefan van der Walt wrote: Matrices strike me as a bit of an anomaly. I would expect an N-dimensional container to contain (N-1)-dimensional objects. Yes indeed. Doesn't seem to be the way the matrix

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Alan G Isaac
On Tue, 27 Mar 2007, Bill Baxter apparently wrote: xformedPt = someComplicatedNonLinearThing(pt) I do stuff like the above quite frequently in my code, although with arrays rather than matrices. Exactly: that was one other thing I found artificial. Surely the points will then be wanted as

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Zachary Pincus
Exactly: that was one other thing I found artificial. Surely the points will then be wanted as arrays. So my view is that we still do not have a use case for wanting matrices yielded when iterating across rows of a matrix. It's pretty clear from my perspective: 1-D slices of matrices *must*

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Christopher Barker
Zachary Pincus wrote: rest of linear algebra -- e.g. that m[0] yields a matrix if m is a matrix-- it almost certainly would violate the principle of least surprise for iteration over m (intuitively understood to be choosing m [0] then m[1] and so forth) to yield anything other than a

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Colin J. Williams
Alan G Isaac wrote: On Mon, 26 Mar 2007, Colin J. Williams apparently wrote: One would expect the iteration over A to return row vectors, represented by (1, n) matrices. This is again simple assertion. **Why** would one expect this? Some people clearly do not. One person commented

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Travis Oliphant
Alan Isaac wrote: On Mon, 26 Mar 2007, Travis Oliphant wrote: It actually has been offered. You just don't accept it. Matrices are containers of matrices. If M is an (mxn) matrix then M[0] is a (1xn) matrix. Viewing this 1xn matrix as a 1-d array loses it's row-vectorness.

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Zachary Pincus
Hello all, I suspect my previous email did not contain the full chain of my reasoning, because I thought that some parts were basically obvious. My point was merely that given some pretty basic fundamental tenants of numpy, Alan's suggestions quickly lead to *serious issues* far worse

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Alan G Isaac
Hi Zach, The use case I requested was for iteration over a matrix where it is desirable that matrices are yielded. That is not what you offered. The context for this request is my own experience: whenever I have needed to iterate over matrices, I have always wanted the arrays. So I am simply

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Robert Kern
Alan G Isaac wrote: Hi Zach, The use case I requested was for iteration over a matrix where it is desirable that matrices are yielded. That is not what you offered. The context for this request is my own experience: whenever I have needed to iterate over matrices, I have always wanted

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Alan G Isaac
On Tue, 27 Mar 2007, Robert Kern apparently wrote: Gram-Schmidt orthogonalization I take it from context that you consider it desirable to end up with a list of matrices? I guess I would find it more natural to work with the arrays, but perhaps that starts just being taste. Thank you, Alan

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Robert Kern
Alan G Isaac wrote: On Tue, 27 Mar 2007, Robert Kern apparently wrote: Gram-Schmidt orthogonalization I take it from context that you consider it desirable to end up with a list of matrices? Honestly, I don't care. You asked about iteration, and I gave you an example where it was

Re: [Numpy-discussion] matrix indexing question

2007-03-27 Thread Alan G Isaac
On Tue, 27 Mar 2007, Robert Kern apparently wrote: Gram-Schmidt orthogonalization Alan G Isaac wrote: I take it from context that you consider it desirable to end up with a list of matrices? Robert wrote: Honestly, I don't care. You asked about iteration, and I gave you an

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Colin J. Williams
Bill Baxter wrote: On 3/26/07, Colin J. Williams [EMAIL PROTECTED] wrote: Bill Baxter wrote: This may sound silly, but I really think seeing all those brackets is what makes it feel wrong. Matlab's output doesn't put it in your face that your 4 is really a matrix([[4]]), even though that's

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Colin J. Williams
Alan G Isaac wrote: On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: finds itself in basic conflict with the idea that I ought to be able to iterate over the objects in an iterable container. I mean really, does this not feel wrong? :: for item in x: print item.__repr__()

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Colin J. Williams
Alan G Isaac wrote: Alan G Isaac wrote: So this :: x[1] matrix([[1, 0]]) feels wrong. (Similarly when iterating across rows.) Of course I realize that I can just :: x.A[1] array([1, 0]) On Sun, 25 Mar 2007, Colin J. Williams apparently wrote: An array and

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Alan G Isaac
On Mon, 26 Mar 2007, Colin J. Williams apparently wrote: Perhaps things would be clearer if we thought of the constituent groups of data in a matrix as being themselves matrices. This thinking of is what you have suggested before. You need to explain why it is not begging the question.

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Alan G Isaac
Alan G Isaac schrieb: X[1] array([3,4]) X[1,:] matrix([[3, 4]]) But again the point is: indexing for submatrices should produce matrices. Normal Python indexing should access the constituent arrays. On Mon, 26 Mar 2007, Sven Schreiber apparently wrote: I think

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Sven Schreiber
Alan G Isaac schrieb: What feels wrong: iterating over a container does not give access to the contained objects. This is not Pythonic. If you iterate over the rows of the matrix, it feels natural to me to get the row vectors -- and as you know a 1d-array does not contain the information

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Alan G Isaac
Alan G Isaac schrieb: What feels wrong: iterating over a container does not give access to the contained objects. This is not Pythonic. On Mon, 26 Mar 2007, Sven Schreiber apparently wrote: If you iterate over the rows of the matrix, it feels natural to me to get the row vectors

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Alan G Isaac
On Mon, 26 Mar 2007, Sebastian Haase apparently wrote: A matrix is an object that you expect a certain (mathematical !) behavior from. If some object behaves intuitively right -- that's ultimately pythonic! The problem is, as I am not the only one to point out, this particular behavior is

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Colin J. Williams
Alan G Isaac wrote: On Mon, 26 Mar 2007, Colin J. Williams apparently wrote: Perhaps things would be clearer if we thought of the constituent groups of data in a matrix as being themselves matrices. This thinking of is what you have suggested before. You need to explain why it is not

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Charles R Harris
On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: On Mon, 26 Mar 2007, Colin J. Williams apparently wrote: One would expect the iteration over A to return row vectors, represented by (1, n) matrices. This is again simple assertion. **Why** would one expect this? Some people clearly do not.

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Alan G Isaac
On Mon, 26 Mar 2007, Colin J. Williams apparently wrote: One would expect the iteration over A to return row vectors, represented by (1, n) matrices. On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: This is again simple assertion. **Why** would one expect this? Some people clearly

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Zachary Pincus
Since matrices are an iterable Python object, we *expect* to iterate over the contained objects. (Arrays.) I am not sure why this is not evident to all, but it is surely the sticking point in this discussion. A matrix is not a container of matrices. That it acts like one is surprsing.

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Travis Oliphant
Alan G Isaac wrote: On Mon, 26 Mar 2007, Colin J. Williams apparently wrote: One would expect the iteration over A to return row vectors, represented by (1, n) matrices. On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: This is again simple assertion. **Why**

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Charles R Harris
On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: On Mon, 26 Mar 2007, Colin J. Williams apparently wrote: One would expect the iteration over A to return row vectors, represented by (1, n) matrices. On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: This is again simple assertion.

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Alan Isaac
On Mon, 26 Mar 2007, Travis Oliphant wrote: It actually has been offered. You just don't accept it. Matrices are containers of matrices. If M is an (mxn) matrix then M[0] is a (1xn) matrix. Viewing this 1xn matrix as a 1-d array loses it's row-vectorness. This seems perfectly

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Alan Isaac
On 3/27/07, Alan Isaac [EMAIL PROTECTED] wrote: May I see a use case where the desired return when iterating through a matrix is rows as matrices? That has never been what I wanted. On Tue, 27 Mar 2007, Bill Baxter wrote: AllMyPoints = mat(rand(100,2)) # 100 two-d points for pt in

Re: [Numpy-discussion] matrix indexing question

2007-03-26 Thread Bill Baxter
On 3/27/07, Alan Isaac [EMAIL PROTECTED] wrote: On 3/27/07, Alan Isaac [EMAIL PROTECTED] wrote: May I see a use case where the desired return when iterating through a matrix is rows as matrices? That has never been what I wanted. On Tue, 27 Mar 2007, Bill Baxter wrote: AllMyPoints

[Numpy-discussion] matrix indexing question

2007-03-25 Thread Alan G Isaac
One thing keeps bugging me when I use numpy.matrix. All this is fine:: x=N.mat('1 1;1 0') x matrix([[1, 1], [1, 0]]) x[1,:] matrix([[1, 0]]) But it seems to me that I should be able to extract a matrix row as an array. So this :: x[1] matrix([[1,

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Paulo Jose da Silva e Silva
Em Dom, 2007-03-25 às 13:07 -0400, Alan G Isaac escreveu: So this :: x[1] matrix([[1, 0]]) feels wrong. (Similarly when iterating across rows.) Of course I realize that I can just :: x.A[1] array([1, 0]) but since the above keeps feeling wrong I felt I should

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Alan G Isaac
Em Dom, 2007-03-25 às 13:07 -0400, Alan G Isaac escreveu: x[1] matrix([[1, 0]]) feels wrong. (Similarly when iterating across rows.) On Sun, 25 Mar 2007, Paulo Jose da Silva e Silva apparently wrote: I think the point here is that if you are using matrices, then all you should

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Bill Baxter
On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: Em Dom, 2007-03-25 às 13:07 -0400, Alan G Isaac escreveu: x[1] matrix([[1, 0]]) feels wrong. (Similarly when iterating across rows.) On Sun, 25 Mar 2007, Paulo Jose da Silva e Silva apparently wrote: I think the point here is

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Colin J. Williams
Alan G Isaac wrote: One thing keeps bugging me when I use numpy.matrix. All this is fine:: x=N.mat('1 1;1 0') x matrix([[1, 1], [1, 0]]) x[1,:] matrix([[1, 0]]) But it seems to me that I should be able to extract a matrix row as an array. This

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Colin J. Williams
Alan G Isaac wrote: Em Dom, 2007-03-25 Ã s 13:07 -0400, Alan G Isaac escreveu: x[1] matrix([[1, 0]]) feels wrong. (Similarly when iterating across rows.) On Sun, 25 Mar 2007, Paulo Jose da Silva e Silva apparently wrote: I think the point here is that if you are using matrices,

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Colin J. Williams
Bill Baxter wrote: On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: Em Dom, 2007-03-25 às 13:07 -0400, Alan G Isaac escreveu: x[1] matrix([[1, 0]]) feels wrong. (Similarly when iterating across rows.) On Sun, 25 Mar 2007, Paulo Jose da Silva e Silva apparently wrote: I think the

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Bill Baxter
On 3/26/07, Colin J. Williams [EMAIL PROTECTED] wrote: Bill Baxter wrote: This may sound silly, but I really think seeing all those brackets is what makes it feel wrong. Matlab's output doesn't put it in your face that your 4 is really a matrix([[4]]), even though that's what it is to

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Alan G Isaac
Alan G Isaac wrote: So this :: x[1] matrix([[1, 0]]) feels wrong. (Similarly when iterating across rows.) Of course I realize that I can just :: x.A[1] array([1, 0]) On Sun, 25 Mar 2007, Colin J. Williams apparently wrote: An array and a matrix are different

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Alan G Isaac
On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: finds itself in basic conflict with the idea that I ought to be able to iterate over the objects in an iterable container. I mean really, does this not feel wrong? :: for item in x: print item.__repr__() ...

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Bill Baxter
On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: finds itself in basic conflict with the idea that I ought to be able to iterate over the objects in an iterable container. I mean really, does this not feel wrong? :: for item in

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Alan G Isaac
On 3/26/07, Alan G Isaac [EMAIL PROTECTED] wrote: finds itself in basic conflict with the idea that I ought to be able to iterate over the objects in an iterable container. I mean really, does this not feel wrong? :: for item in x: print item.__repr__() ... matrix([[1,

Re: [Numpy-discussion] matrix indexing question

2007-03-25 Thread Alan G Isaac
Oooops, they should match of course. :: X[1] array([3,4]) X[1,:] matrix([[3, 4]]) But again the point is: indexing for submatrices should produce matrices. Normal Python indexing should access the constituent arrays. Cheers, Alan Isaac