From: Keith G. <kwg...@gm...> - 2006-07-07 15:45:24
|
On 7/7/06, Ed Schofield <sch...@ft...> wrote: > I'd like to help to make matrices more usable. Tell me what you want, > and I'll work on some patches. I can't pass up an offer like that. DIAG diag(M) returns an array. It would be nice if diag(M) returned asmatrix(diag(M)).T. It would also be nice if you can construct a diagonal matrix directly from what is returned from diag(M). But right now you can't: >> x matrix([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >> diag(x) array([0, 4, 8]) >> d = asmatrix(diag(x)).T >> d matrix([[0], [4], [8]]) >> diag(d) array([0]) <-- this should be a 3x3 matrix MATRIX CONSTRUCTION Making it easier to construct matrices would be a big help. Could the following function be made to return matrices? ones, zeros, rand, randn, eye, linspace, empty I guess the big decision is how to tell numpy to use matrices. How about from numpy.matrix import ones, zeros ? I would prefer something even more global. Something that acts like the global variable 'usematrix = True'. Once that is declared, the default changes from array to matrix. INDEXING >> x matrix([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >> y matrix([[0], [1], [2]]) >> x[y>1,:] matrix([[6]]) This is a big one for me. If x[y>1,:] returned >> x[2,:] matrix([[6, 7, 8]]) then there would no longer be a need for array :) |