开发者

Passing numpy arrays to Java using Jpype

开发者 https://www.devze.com 2023-03-08 06:52 出处:网络
I am trying to convert a numpy array into a Java-like array using JPype\'s JArray command. values = valBD.ReadAsArray()

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

values = valBD.ReadAsArray()
JArray(fl开发者_如何学运维oat, 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


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

Try this:

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


The other answer doesn't work. Try this:

a = JArray(JFloat,1)([1.5,2.0])
0

精彩评论

暂无评论...
验证码 换一张
取 消