Help me on function definition

castironpi at gmail.com castironpi at gmail.com
Sun Mar 30 01:37:07 EDT 2008


On Mar 29, 11:45 pm, hdante <hda... at gmail.com> wrote:
> On Mar 28, 10:47 pm, "aeneng" <aen... at yahoo.com> wrote:
>
> > Hello everyone,
>
>  Hi,
>
>  Always avoid reinventing the wheel:
>
> from Numeric import array, cross_product
> a = array([1, 2, 3])
> b = array([4, 5, 6])
> print cross_product(a, b)
>
>  See:
>  http://numpy.scipy.org/
>  http://www.scipy.org/
>
>  (hint: consider that many people want to multiply matrices) :-)
>
>
>
>
>
> > I am just starting to use python in numerical cacluation.
> > I need you to help me to see what's wrong with the following piece of
> > codes, which computes the cross product of two vectors and returns
> > the result. u and v are two 3x1 matrix.
>
> > when I import the function, error message show like this>>> import cross
>
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> >   File "cross.py", line 8
> >     ppp2=u[2]*v[0]-u[0]*v[2]
> >     ^
> > SyntaxError: invalid syntax
>
> > WHAT IS WRONG WITH MY CODE?
>
> > I appreciate your help.
>
> > ##here is the function definition.
> > ##cross.py##
> > def cross(u,v)
> >     """input two vectors u and v in 3-D space,
> >        output a cross product of vector w, in column or in row
> > accordingly."""
> >     ppp1,ppp2,ppp3=0.0,0.0,0.0
> >     ppp1=u[1]*v[2]-u[2]*v[1]
> >     ppp2=u[2]*v[0]-u[0]*v[2]
> >     ppp3=u[0]*v[1]-u[1]*v[0]
> >     # store the result of the cross product in u
> >     u[0]=ppp1
> >     u[1]=ppp2
> >     u[2]=ppp3
> >     return u #return the cross product of vector u x v.
> > if __name__=="__main__":
> >         from cvxopt.base import matrix
> >         u=matrix([1.0,0.0,0.0],(3,1))
> >         v=matrix([0.0,1.0,0.0],(3,1))
> >         print cross(u,v)
> >         print "file name is %s" %__name__- Hide quoted text -

Bandwidth is really low; offload logic.  I'd run some AI for the games
so you can get a couple more triangles... plot.thicken()



More information about the Python-list mailing list