One problem with the matrix class is that it follows matlab way too much. For 
example:

>>> a = arange(9).reshape(3,3)
>>> A = asmatrix(a)
>>> v = arange(3)
>>> dot(a, v)
array([ 5, 14, 23])
>>> A*v

Traceback (most recent call last):
  File "<pyshell#15>", line 1, in <module>
    A*v
  File "C:\Python25\lib\site-packages\numpy\core\defmatrix.py", line 157, in 
__mul__
    return N.dot(self, asmatrix(other))
ValueError: objects are not aligned

I do a lot of colour image processing. Most of the time I treat an image as a 
MxNx3 array, but some time I have to do matrix/ vector operations like 
colour-space conversion. In these cases the dot function becomes very handy 
(better then Matlab matrix multiplication), since I can write:

new_image = dot(old_image, A)

where A is either a 3x3 matrix or a length 3 vector. The result is that my code 
is cluttered with a lot of "dot"s, and the matrix class can not help much. It 
is possible that my case is special and does not justify a special attention, 
but if many of us do colour/spectral imaging, or other type of high-rank 
tensors algebra, there could be a case to give numpy an edge.

   Nadav.



-----הודעה מקורית-----
מאת: [EMAIL PROTECTED] בשם Travis E. Oliphant
נשלח: ש 22-מרץ-08 01:12
אל: Discussion of Numerical Python
נושא: Re: [Numpy-discussion] matrices in 1.1
 
Charles R Harris wrote:
>
>
> On Fri, Mar 21, 2008 at 1:57 PM, Alan G Isaac <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>     On Fri, 21 Mar 2008, Nadav Horesh apparently wrote:
>     > But asmatrix returns a matrix object and any subsequent
>     > operation of it returns a matrix. What I am thinking about
>     > is a convenient way to apply matrix operation on an array.
>
>     I suspect what you are really wanting is a way for NumPy to
>     define new operators ...
>
>
> I still kinda like the idea of using the call operator for matrix 
> multiplication, i.e. A(v) := dot(A,v).
Interesting idea.    I kind of like that too.

-Travis


_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

<<winmail.dat>>

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to