From: Updike, C. <Cla...@jh...> - 2003-06-05 15:51:21
|
Maybe this will help: Jython 2.1 on java1.3.1_01 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import java >>> m=java.lang.reflect.Array.newInstance(java.lang.Float.TYPE,[3,3]) >>> for row in m: ... for cell in row: ... print "OK" ... OK OK OK OK OK OK OK OK OK >>> -Clark -----Original Message----- From: ikke ekki [mailto:bas...@ho...] Sent: Thursday, June 05, 2003 9:42 AM To: Jyt...@li... Subject: [Jython-users] java 2 dimensional array in Jython Hi, My problem is the following: I want to pass a multi dimensional array from my java program to the PythonInterpreter. I do this as follows: PythonInterpreter interp=new PythonInterpreter(); Float[][] inputMatrix=new Float[3][3]; interp.set("matrix",inputMatrix); This has strange behaviour in my python script if I do the following I get 30 entries for y in matrix: for z in y: print("OK") I get 30 times OK instead of 9 If I create a 2 by 2 matrix I get 10 OK So I guess I'll get for a X by X matrix X*X+1 times OK Does anyone know how I can set the matrix into the interpreter and how to get it back? For getting it back I do the following: Float[][] resultMatrix = (Float[][]) interp.get("matrix",Float[][].class); This matrix is a 3 by 10 matrix, this explains the 30 OK's Can someone help me and explain what happens exactly? Where did my original 3 by 3 matrix go? Thank you very much _________________________________________________________________ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail ------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The best thread debugger on the planet. Designed with thread debugging features you've never dreamed of, try TotalView 6 free at www.etnus.com. _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |
From: nr n. <new...@ho...> - 2003-06-06 00:00:33
|
Clark's response should take care of java-to-jython; see the following for the reverse: http://www.jython.org/docs/jarray.html --A ----Original Message Follows---- From: "ikke ekki" <bas...@ho...> To: Jyt...@li... Subject: [Jython-users] java 2 dimensional array in Jython Date: Thu, 05 Jun 2003 13:42:21 +0000 Hi, My problem is the following: I want to pass a multi dimensional array from my java program to the PythonInterpreter. I do this as follows: PythonInterpreter interp=new PythonInterpreter(); Float[][] inputMatrix=new Float[3][3]; interp.set("matrix",inputMatrix); This has strange behaviour in my python script if I do the following I get 30 entries for y in matrix: for z in y: print("OK") I get 30 times OK instead of 9 If I create a 2 by 2 matrix I get 10 OK So I guess I'll get for a X by X matrix X*X+1 times OK Does anyone know how I can set the matrix into the interpreter and how to get it back? For getting it back I do the following: Float[][] resultMatrix = (Float[][]) interp.get("matrix",Float[][].class); This matrix is a 3 by 10 matrix, this explains the 30 OK's Can someone help me and explain what happens exactly? Where did my original 3 by 3 matrix go? _________________________________________________________________ MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus |