Re: [Numpy-discussion] New Operators in Python
Em Seg, 2007-03-26 às 01:08 +1000, dpn escreveu: With the possible inclusion of generic functions in py3k I dont really see the point of adding more operators. (While i do miss mat1 x mat2 from PDL). mat3 = mat1.mm(mat2) or the like seems to be sufficient. I find matrix multiplication annoying in the case of SVD reconstruction: final = matrixmultiply(matrixmultiply(u, s), v) Matrix multiplication is just too common in numerical linear algebra, one of the main areas for numpy/scipy. Even though I can get used with using dot (or matrixmultiply) to do it, I can easily see the benefit of having a special operator here. This will be beneficial for mathematicians that use numpy/scipy to prototype some ideas or to newcomers from Matlab. Paulo -- Paulo José da Silva e Silva Professor Assistente do Dep. de Ciência da Computação (Assistant Professor of the Computer Science Dept.) Universidade de São Paulo - Brazil e-mail: [EMAIL PROTECTED] Web: http://www.ime.usp.br/~rsilva Teoria é o que não entendemos o (Theory is something we don't) suficiente para chamar de prática. (understand well enough to call practice) ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] matrix indexing question
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 raise this as a possible design issue, better discussed early than latter. I think the point here is that if you are using matrices, then all you should want are matrices, just like in MATLAB: A = [1 2; 3 4] A = 1 2 3 4 b = A(1, :) b = 1 2 size(b) ans = 1 2 b = A(:, 1) b = 1 3 size(b) ans = 2 1 b = 1 b = 1 size(b) ans = 1 1 You see, rows, columnes, and even numbers, are treated as matrices. Paulo -- Paulo José da Silva e Silva Professor Assistente do Dep. de Ciência da Computação (Assistant Professor of the Computer Science Dept.) Universidade de São Paulo - Brazil e-mail: [EMAIL PROTECTED] Web: http://www.ime.usp.br/~rsilva Teoria é o que não entendemos o (Theory is something we don't) suficiente para chamar de prática. (understand well enough to call practice) ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Automatic matrices
Hello, If a numpy user is specially concerned with numerical linear algebra (or more generally with Math), it may find unconvenient the use of the dot function instead of the * operator. This behavior may be specially unpleasant for someone migrating from Matlab. I believe that this is the may reason for the existence of the matrix class within numpy. However, after trying to use the matrix class I have came across a major roadblock: many numpy/scipy functions return an array by default and not matrices. Then, we need then to add many conversion calls to the 'mat' function in our code. This is also unconvenient. I have had the idea of trying to write some code to automatically call the mat function for me. I have a very simple and inefficient prototype now that can be downloaded at: http://www.ime.usp.br/~pjssilva/matrix_import.py The use is simple. Instead of importing a numerical module with import, use the special class MatrixfiedModule from the above file. Let me give an example: --- ipython session --- In [2]:import matrix_import as mi In [3]:num = mi.MatrixfiedModule('numpy') Importing numpy In [4]:la = mi.MatrixfiedModule('scipy.linalg') Importing scipy.linalg In [5]:A = num.random.rand(3,4) Importing numpy.random In [6]:Q, R = la.qr(A) In [7]:la.norm(Q*R - A) Out[7]:6.016793379748e-16 - End session - For now the solution is very inefficient: every function call to a MatrixfiedModule function is wrapped on the fly to search for array return values ad convert them to matrix. This can certainly be improved the wrapping all the functions in the original module first. I plan to add this possibility soon. It is also incomplete: The automatic conversion only happens for return values of module function. It doesn't try to deal with special objects like finfo(float).eps or mgrid[0:9.,0:6.]. I am not sure how to deal with this. I can donate the code to scipy if there is any interest. Any comments? Best, Paulo -- Paulo José da Silva e Silva Professor Assistente, Dep. de Ciência da Computação (Assistant Professor, Computer Science Dept.) Universidade de São Paulo - Brazil e-mail: [EMAIL PROTECTED]Web: http://www.ime.usp.br/~pjssilva Teoria é o que não entendemos o(Theory is something we don't) suficiente para chamar de prática. (understand well enough to call) (practice) ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion