Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing numpy arrays to Java using Jpype

Tags:

java

python

numpy

I am trying to convert a numpy array into a Java-like array using JPype's JArray command.

values = valBD.ReadAsArray()
JArray(float, values.ndim)(values)

leads to the following error message:

JArray(float, values.ndim)(values) File "c:\Python26\lib\site-packages\jpype_jarray.py", line 125, in JArray elif issubclass(t, _jclass._JAVAOBJECT):

TypeError: issubclass() arg 2 must be a class or tuple of classes

Do you habe any suggesions? Thanks a lot, Martwig

like image 336
Mario Härtwig Avatar asked Jan 27 '26 06:01

Mario Härtwig


1 Answers

JPype is expecting a list or list of lists, not a numpy array.

Try this:

values = valBD.ReadAsArray()
JArray(float, values.ndim)(values.tolist())
like image 118
Nick ODell Avatar answered Jan 28 '26 20:01

Nick ODell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!