Re: Newbie question about numpy

2006-08-25 Thread Paul Johnston
On Thu, 24 Aug 2006 17:23:49 GMT, Dennis Lee Bieber
<[EMAIL PROTECTED]> wrote:

>On Thu, 24 Aug 2006 16:38:45 +0100, Paul Johnston
><[EMAIL PROTECTED]> declaimed the following in
>comp.lang.python:
>
>> I know its a long time since my degree but that's not matrix
>> multiplication is it ?
>
>   Define "matrix multiplication"...
>
>   What you see appears to be multiplication of corresponding elements.
>
>   Were you expecting a dot product, or a cross product, or something
>else?
>

That as explained in
http://people.hofstra.edu/faculty/stefan_Waner/RealWorld/tutorialsf1/frames3_2.html

As I say its been a long time :-)

Thanks to everyone for the help.
Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about numpy

2006-08-24 Thread Robert Kern
Avell Diroll wrote:

> For matrices multiplication, you could get a hint by typing the
> following in the interpreter :
> 
 import numpy
 dir(numpy)
 help(numpy.matrixmultiply)#type "q" to exit

Note that the name matrixmultiply() has been deprecated in favor of dot() for 
many, many years now even in Numeric, numpy's predecessor. It has finally been 
removed in recent versions of numpy.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about numpy

2006-08-24 Thread Avell Diroll
Paul Johnston wrote:
(snip)
> I noted the lack of matrices so installed numpy
(snip)
> _
> from numpy  import *
> 
> a = array([[1,2,3],[4,5,6],[1,2,3]])
> b = array([[1,3,6],[2,5,1],[1,1,1]])
(snip)
> print "a * b is \n", a * b
> _
(snip)
> a * b is
> [[ 1  6 18]
>  [ 8 25  6]
>  [ 1  2  3]]
> _
> 
> 
> I know its a long time since my degree but that's not matrix
> multiplication is it ?

You consider that a and b are matrices, but for the python interpreter
they are arrays so a*b returns the multiplication of 2 arrays.

For matrices multiplication, you could get a hint by typing the
following in the interpreter :

>>> import numpy
>>> dir(numpy)
>>> help(numpy.matrixmultiply)#type "q" to exit

which could make you want to try the following code :

>>> from numpy  import *
>>> a = array([[1,2,3],[4,5,6],[1,2,3]])
>>> b = array([[1,3,6],[2,5,1],[1,1,1]])
>>> print matrixmultiply(a,b)

...
output :
...

array([[ 8, 16, 11],
   [20, 43, 35],
   [ 8, 16, 11]])
...

HIH,
avell

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about numpy

2006-08-24 Thread Robert Kern
Paul Johnston wrote:
> Hi I'm new to python and have just been taking a look at what it has
> to offer.
> I noted the lack of matrices so installed numpy

You will want to ask numpy questions on the numpy list.

   http://www.scipy.org/Mailing_Lists

numpy arrays are not matrices; they are arrays. All of the arithmetic 
operations 
on them are done element-wise. The dot() function will do matrix multiplication.

There is a matrix class (with the constructor numpy.mat(some_array)) that 
derives from arrays and overrides the * operator to do matrix multiplication if 
that is what you want. I prefer using dot() on regular arrays, myself.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about numpy

2006-08-24 Thread Gabriel Genellina

At Thursday 24/8/2006 12:38, Paul Johnston wrote:


from numpy  import *

a = array([[1,2,3],[4,5,6],[1,2,3]])
b = array([[1,3,6],[2,5,1],[1,1,1]])
print "a * b is \n", a * b

I know its a long time since my degree but that's not matrix
multiplication is it ?


No, it's plain element-by-element multiplication.
You want matrixmultiply: 
http://numpy.scipy.org/numpydoc/numpy-9.html#pgfId-36542




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


-- 
http://mail.python.org/mailman/listinfo/python-list

Newbie question about numpy

2006-08-24 Thread Paul Johnston
Hi I'm new to python and have just been taking a look at what it has
to offer.
I noted the lack of matrices so installed numpy
I know the documentation is chargable so wanted a quick play to see if
I should buy it 
However 

_
from numpy  import *

a = array([[1,2,3],[4,5,6],[1,2,3]])
b = array([[1,3,6],[2,5,1],[1,1,1]])

print 'a = \n',a,"\n"
print 'b = \n',b,"\n"

print 'a has shape ', a.shape
print 'b has shape ', b.shape, "\n"

print "a * b is \n", a * b
_

Gives me 
_
a =
[[1 2 3]
 [4 5 6]
 [1 2 3]] 

b =
[[1 3 6]
 [2 5 1]
 [1 1 1]] 

a has shape  (3, 3)
b has shape  (3, 3) 

a * b is
[[ 1  6 18]
 [ 8 25  6]
 [ 1  2  3]]
_


I know its a long time since my degree but that's not matrix
multiplication is it ?

TIA Paul
-- 
http://mail.python.org/mailman/listinfo/python-list