From: JJ <jos...@ya...> - 2006-07-11 23:17:11
|
Hello. For what its worth, as a newly ex-matlab user I would like to make a few suggestions on use of matrices in numpy. As per earlier discussions, I like the idea of being able to choose matrices as the default (vs arrays). But if possible, it would be nice if all functions etc that took matrices also returned matrices. I know effort has been made on this. Here are my suggestions: 1) is it possible to get the function unique() to work with matrices, perhaps with a unique_rows() function to work with matrices of more than one column? 2) It would be very convienient to have some simple way to delete selected columns of a matrix. For example, in matlab the command is X[:,[3,5,7]]=[] to delete the three selected columns. It would be nice if such a command would also work with selections, as in X[:,A[0,:]<4] = [], where X and A are matrices. For me, the single most frustrating and time-consuming aspect of switching to and using numpy is determing how to select columns/rows of arrays/matrices in different situations. In addition to being time consuming to figure out (relative to Matlab), often the code is quite verbose. I have made a few suggestions on this topic in an earlier post (under the title "Whats wrong with matrices?"). 3) It would be nice if matrices could be used for iterations. For example, if M was a 1 x n matrix, it would be nice to be able to use: for i in M: and iterate over the individual items in M. 4) It would be nice if the linear algebra package and other packages returned matrices if given matrices. For example, if M is a matrix, svd(M) now returns arrays. Just some suggestions. I wish I knew more so I could help implement them. Maybe one day. JJ |
From: Travis O. <oli...@ee...> - 2006-07-11 23:41:56
|
JJ wrote: >Hello. For what its worth, as a newly ex-matlab user I would like to make a few >suggestions on use of matrices in numpy. As per earlier discussions, I like the >idea of being able to choose matrices as the default (vs arrays). But if >possible, it would be nice if all functions etc that took matrices also returned >matrices. I know effort has been made on this. Here are my suggestions: > >1) is it possible to get the function unique() to work with matrices, perhaps >with a unique_rows() function to work with matrices of more than one column? > >2) It would be very convienient to have some simple way to delete selected >columns of a matrix. > This is a good idea. It would be nice to address it at some point. There is a Python syntax for it, but we are not using it yet: del X[...] Of course one of the problems with this syntax (as opposed to a function that returns a new array) is that because X can share it's data with other arrays, you can't just re-size it's memory or other arrays depending on that chunk of memory will be in deep trouble. So, we are probably not going to be able to have a "syntax-style" delete. But, some kind of function that returns an array with specific entries deleted would be nice. >3) It would be nice if matrices could be used for iterations. For example, if M >was a 1 x n matrix, it would be nice to be able to use: for i in M: and >iterate over the individual items in M. > > They can be used as iterators. The problem here is simply convention (rows are iterated over first). We could over-ride the iterator behavior of matrices, though to handle 1xn and nx1 matrices identically if that is desirable. >4) It would be nice if the linear algebra package and other packages returned >matrices if given matrices. For example, if M is a matrix, svd(M) now returns > > Svd returns matrices now. Except for the list of singular values which is still an array. Do you want a 1xn matrix instead of an array? -Travis |
From: Keith G. <kwg...@gm...> - 2006-07-12 00:11:15
|
On 7/11/06, Travis Oliphant <oli...@ee...> wrote: > JJ wrote: > >4) It would be nice if the linear algebra package and other packages returned > >matrices if given matrices. For example, if M is a matrix, svd(M) now returns > > > > > Svd returns matrices now. Except for the list of singular values which > is still an array. Do you want a 1xn matrix instead of an array? That sounds good to me. The same goes for eig and eigh: >> eigval,eigvec = linalg.eig(rand(2,2)) >> eigval array([-0.06035002, 0.14320639]) >> eigvec matrix([[ 0.54799954, -0.83647863], [-0.83647863, -0.54799954]]) |
From: JJ <jos...@ya...> - 2006-07-12 00:23:50
|
Travis Oliphant <oliphant <at> ee.byu.edu> writes: > But, some kind of function that returns an array with specific > entries deleted would be nice. I agree. This would be just fine. > We could over-ride the iterator > behavior of matrices, though to handle 1xn and nx1 matrices > identically if that is desirable. I had tried this iteration on a month-old version of numpy and it did not work. I guess this now has been changed. I just updated my copy but have not yet tried it. An over-ride might be nice. But just off the topic, could you get a matrix of real numbers such as A= [[1.0 2.0,3.0]] to be used to select rows/colums as in B[:,A]? I guess this would require a hidden conversion to integers, as well as code to handle selection using a matrix. > Svd returns matrices now. Except for the list of singular values > which is still an array. Do you want a 1xn matrix instead of an > array? I had just tried this with my new version of numpy, but I had used svd as follows: import scipy.linalg as la res = la.svd(M) That returned arrays, but I see that using: res = linalg.svd(M) returns matrices. Apparently, both numpy and scipy have linalg packages, which differ. I did not know that. Whoops. |
From: Sven S. <sve...@gm...> - 2006-07-12 09:45:06
|
JJ schrieb: > Travis Oliphant <oliphant <at> ee.byu.edu> writes: > >> Svd returns matrices now. Except for the list of singular values >> which is still an array. Do you want a 1xn matrix instead of an >> array? Although I'm a matrix supporter, I'm not sure here. Afaics the pro argument is to have *everything* a matrix when you're in that camp. Fair enough. But then it's already not clear if you want a row or a column, and you carry an extra dimension around, which is sometimes annoying e.g. for cumulation of the values, which I do a lot (for eigenvalues, that is). So for my personal use I came to the conclusion that the status quo of numpy (array for the value list, matrix for the decomp) is just fine. So maybe the people in favor of values-in-1xn-matrices can tell why they need to matrix-multiply the value array afterwards, because that's the only benefit I can see here. > > I had just tried this with my new version of numpy, but I had used svd > as follows: > import scipy.linalg as la > res = la.svd(M) > That returned arrays, but I see that using: > res = linalg.svd(M) > returns matrices. Apparently, both numpy and scipy have linalg > packages, which differ. I did not know that. Whoops. > I'm trying to get by with numpy (good that kron was brought over!), but eventually I will need scipy -- I was hoping that all the matrix discussion in the numpy list implicitly applied to scipy as well. Is that not true? Cheers, Sven |
From: Michael S. <mic...@gm...> - 2006-07-12 00:07:57
|
On 7/12/06, JJ <jos...@ya...> wrote: > 2) It would be very convienient to have some simple way to delete selected > columns of a matrix. For example, in matlab the command is X[:,[3,5,7]]=[] to > delete the three selected columns. It would be nice if such a command would > also work with selections, as in X[:,A[0,:]<4] = [], where X and A are matrices. +1. In R negative integers are used for this purpose and a copy of the array is returned. e.g. > x = 1:10 > x [1] 1 2 3 4 5 6 7 8 9 10 > x[-1] [1] 2 3 4 5 6 7 8 9 10 > x[c(-1,-2)] [1] 3 4 5 6 7 8 9 10 > x[-c(1,2)] [1] 3 4 5 6 7 8 9 10 I like the current use of negative indices in numpy, but I do find myself missing the ability to easily make a copy of the array without certain indices. Mike |
From: Johannes L. <a.u...@gm...> - 2006-07-12 07:10:51
|
On Wednesday 12 July 2006 02:07, Michael Sorich wrote: > On 7/12/06, JJ <jos...@ya...> wrote: > > 2) It would be very convienient to have some simple way to delete > > selected columns of a matrix. For example, in matlab the command is > > X[:,[3,5,7]]=[] to delete the three selected columns. It would be nice > > if such a command would also work with selections, as in X[:,A[0,:]<4] = > > [], where X and A are matrices. > (...) > I like the current use of negative indices in numpy, but I do find > myself missing the ability to easily make a copy of the array without > certain indices. Maybe use complex numbers? draft: >>> a = arange(10) >>> print a[ 3j ] [ 0 1 2 4 5 6 7 8 9 ] Johannes |
From: David H. <dav...@gm...> - 2006-07-12 02:42:26
|
2006/7/11, JJ <jos...@ya...>: > > 1) is it possible to get the function unique() to work with matrices, > perhaps > with a unique_rows() function to work with matrices of more than one > column? The problem is that applying unique to different rows will return vectors with different lengths. So you could not return an array, much less a matrix. You'd have to return a list of arrays or 1D matrices. David |
From: Keith G. <kwg...@gm...> - 2006-07-12 02:50:49
|
On 7/11/06, David Huard <dav...@gm...> wrote: > > > 2006/7/11, JJ <jos...@ya...>: > > 1) is it possible to get the function unique() to work with matrices, > perhaps > > with a unique_rows() function to work with matrices of more than one > column? > > > The problem is that applying unique to different rows will return vectors > with different lengths. So you could not return an array, much less a > matrix. ...unless it returned the unique rows instead of the unique elements in each row. So if the matrix is 1 2 2 3 4 5 1 2 2 then the unique rows would be 1 2 2 3 4 5 |
From: JJ <jos...@ya...> - 2006-07-12 05:01:21
|
> ...unless it returned the unique rows instead of the > unique elements > in each row. So if the matrix is > > 1 2 2 > 3 4 5 > 1 2 2 > > then the unique rows would be > > 1 2 2 > 3 4 5 > Hello Keith. Yes, that is what I mean also. JJ __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |