From: JJ <jos...@ya...> - 2006-10-10 06:17:35
|
Hello. I haven't been following development too closely lately, but I did just download and reinstall the current svn version. For what its worth, I would like to again suggest two changes: -- If M is a nxm matrix and P and Z are nx1 (or 1xn) matrices, then it would be nice if we could write M[P==Z,:] to obtain all columns and only those rows where P==Z. Likewise, for 1xm (or mx1) matrices U and V, it would be nice to be able to use M[P==Z,U==V]. Also, it would be nice to use M[P==Z,U==2], for example, to obtain selected rows where matrix U is equal to a constant. -- It would be nice to slice a matrix by using M[[1,2,3],[3,5,7]], for example. I believe this would help make indexing more user friendly. In my humble opinion, I think indexing is a weak spot in numpy. I find that most of my debugging involves finding the right code to make a matrix slice the way I want it. John __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |
From: Travis O. <oli...@ie...> - 2006-10-10 06:51:15
|
JJ wrote: > Hello. > I haven't been following development too closely > lately, but I did just download and reinstall the > current svn version. For what its worth, I would like > to again suggest two changes: > Suggestions are nice. Working code is better. Many ideas are just too difficult to implement (and still work with the system as it exists) and so never get done. I'm not saying these ideas fit into this category, but generally if a suggestion is not taken it's very likely seen in that light. > -- If M is a nxm matrix and P and Z are nx1 (or 1xn) > matrices, then it would be nice if we could write > M[P==Z,:] to obtain all columns and only those rows > where P==Z. This works already if p and z are 1-d arrays. That seems to be the only issue. you want this to work with p and z being 2-d arrays (i.e. matrices). The problem is there is already a defined behavior for this case that would have to be ignored (i.e. special-cased to get what you want). This could be done within the special matrix sub-class of course, but I'm not sure it is wise. Too many special cases make life difficult down the road. It is better to just un-think the ambiguity between 1-d and 2-d arrays that was inspired by Matlab and recognize a 1-d situation when you have it. But, that's just my opinion. I'm not dead-set against special-casing in the matrix object if enough matrix-oriented people are in favor of it. But, it would be a feature for a later NumPy (not 1.0). > Likewise, for 1xm (or mx1) matrices U and > V, it would be nice to be able to use M[P==Z,U==V]. > Same issue as before + cross-product versus element-by-element. > Also, it would be nice to use M[P==Z,U==2], for > example, to obtain selected rows where matrix U is > equal to a constant. > Again. Form the cross-product using ix_(). > -- It would be nice to slice a matrix by using > M[[1,2,3],[3,5,7]], for example. > You can get the cross-product using M[ix_([1,2,3],[3,5,7])]. This was a design choice and I think a good one. It's been discussed before. > I believe this would help make indexing more user > friendly. In my humble opinion, I think indexing is a > weak spot in numpy. I'm sorry you see it that way. I think indexing is a strength of numpy. It's a little different then what you are used to with Matlab, perhaps, but it is much more general-purpose and capable (there is one weak-spot in that a certain boolean indexing operations uses more memory than it needs to, but that is a separate issue...). The Matlab behavior can always be created in a sub-class. Best regards, -Travis |
From: Alan G I. <ai...@am...> - 2006-10-10 13:21:57
|
> JJ wrote: >> In my humble opinion, I think indexing is a weak spot in >> numpy. On Tue, 10 Oct 2006, Travis Oliphant apparently wrote: > I'm sorry you see it that way. I think indexing is a strength of > numpy. It's a little different then what you are used to > with Matlab, perhaps, but it is much more general-purpose > and capable I am finding numpy indexing to be great, but it would be helpful perhaps to new users to have a few of the examples from this thread make it to the Cookbook http://www.scipy.org/Cookbook/BuildingArrays Sorry, I cannot do that at the moment. Maybe JJ would find this a profitable exercise? Cheers, Alan Isaac |
From: jj <jos...@ya...> - 2006-10-10 13:20:11
|
> > -- If M is a nxm matrix and P and Z are nx1 (or 1xn) > > matrices, then it would be nice if we could write > > M[P==Z,:] to obtain all columns and only those rows > > where P==Z. > This works already if p and z are 1-d arrays. That seems to be the > only issue. you want this to work with p and z being 2-d arrays (i.e. > matrices). The problem is there is already a defined behavior for this > case that would have to be ignored (i.e. special-cased to get what you > want). This could be done within the special matrix sub-class of > course, but I'm not sure it is wise. Too many special cases make life > difficult down the road. > Thanks for the thoughtful reply Travis. I see I will just have to get used to using code such as M[(P==Z).A.ravel(),:], which I can live with. Your comments helped put this in perspective for me. By the way, is there a web site that lists all the current modules (as does http://www.scipy.org/doc/api_docs/scipy.html)? Best, John |