Re: Help me on function definition
aeneng wrote: WHAT IS WRONG WITH MY CODE? def cross(u,v) Missing colon. hth, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
aeneng schreef: Hello everyone, 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 You forgot the : after def cross(u, v) -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
On Mar 29, 4:18 am, Roel Schroeven [EMAIL PROTECTED] wrote: aeneng schreef: Hello everyone, 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 You forgot the : after def cross(u, v) No; directional is only signed and unsigned. /tangent There's a laptop on my computer. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
aeneng [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | 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 To add to other comments, remove above which is complete waste. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
On Mar 28, 10:47 pm, aeneng [EMAIL PROTECTED] 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__ -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
On Mar 29, 11:45 pm, hdante [EMAIL PROTECTED] wrote: On Mar 28, 10:47 pm, aeneng [EMAIL PROTECTED] 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() -- http://mail.python.org/mailman/listinfo/python-list
Help me on function definition
Hello everyone, 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__ -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
No problem... your def needs a colon.. def function(params): yours lacks it =) thats all On Fri, Mar 28, 2008 at 8:47 PM, aeneng [EMAIL PROTECTED] wrote: Hello everyone, 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__ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
On Sat, 29 Mar 2008 01:47:21 +, aeneng wrote: Hello everyone, 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? You don't win any points by writing the most unreadable code can you. A little bit of white space makes the code so much easier to read: ppp2 = u[2]*v[0] - u[0]*v[2] But that's not the problem. Your code mixes spaces and tabs for indentation. Spaces are good; tabs are good; both together will eventually lead to disaster. But that's not your problem either. Your REAL problem is that the error you are reporting is NOT the error your code gives. Hint: if your code raises an error, you must copy the code that actually raises an error, not different code with different errors. The code you post reports this error: import cross Traceback (most recent call last): File stdin, line 1, in module File cross.py, line 1 def cross(u,v) ^ SyntaxError: invalid syntax After fixing that fault (put a colon after the function definition), your code imports correctly. My *guess* is that in your actual code that fails, you have forgotten to close a bracket or brace in line 7 (not 8). -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
aeneng [EMAIL PROTECTED] writes: I am just starting to use python in numerical cacluation. Welcome, and congratulations on learning Python. I need you to help me to see what's wrong with the following piece of codes [...] Your code is rather difficult to read, since your expressions have all the characters mashed together without spaces. It will help others who read your code if you follow the Python coding guidelines in PEP 8 URL:http://www.python.org/dev/peps/pep-0008. You should also choose names that are descriptive when someone reads the code, and not single-character algebraic names. 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 suspect you will gain enlightenment in this case by running your code via 'python -t foo.py' where 'foo.py' is the Python module you're trying to run. (You can see a description of that option with 'python -h' to display the commandline help.) -- \I have one rule to live by: Don't make it worse. -- Hazel | `\ Woodcock | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
Oh, I forgot to mention... On Sat, 29 Mar 2008 01:47:21 +, aeneng wrote: if __name__==__main__: ... print file name is %s %__name__ This doesn't do what you expect it to do. You've already established that __name__ is equal to __main__, so you might as well change that line to: print file name is not actually __main__ What you want is: print file name is %s % __file__ -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me on function definition
On Mar 29, 12:47 pm, aeneng [EMAIL PROTECTED] wrote: Hello everyone, 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. And you are stuffing the result into the first argument as well as returning the result ... not a good idea. 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__ -- http://mail.python.org/mailman/listinfo/python-list