Message12434

Author adamburke
Recipients adamburke, waynelloydsmith
Date 2019-04-13.11:36:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1555155405.96.0.993472650014.issue2758@roundup.psfhosted.org>
In-reply-to
Content
This should already be possible in Jython. There is an overloaded version of jarray.array() which takes a java.lang.Class object instead of a string description. As arrays are first class objects in Java, once you obtain the class object, you can pass that to create a 2D array of the appropriate type. It helps to know that "[I" is the name of the class for int[] (ie an array of int). See 10.8 here:

https://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html
https://www.geeksforgeeks.org/array-primitive-type-object-java/

Example using jython console

 
Jython 2.7.2a1+ (, Apr. 11 2019, 17:41:34)
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java11.0.1
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.lang import Class
>>> import jarray
>>>
>>> ci = Class.forName('[I')
>>> jarray.array([[1],[2]],ci)
array([I, [array('i', [1]), array('i', [2])])
>>>
>>> cf = Class.forName('[F')
>>> jarray.array([[1.0,1.0],[2.0,2.0]],cf)
array([F, [array('f', [1.0, 1.0]), array('f', [2.0, 2.0])])
>>>
History
Date User Action Args
2019-04-13 11:36:45adamburkesetmessageid: <1555155405.96.0.993472650014.issue2758@roundup.psfhosted.org>
2019-04-13 11:36:45adamburkesetrecipients: + adamburke, waynelloydsmith
2019-04-13 11:36:45adamburkelinkissue2758 messages
2019-04-13 11:36:45adamburkecreate