0

What is the fastest and best way to return a large data array from Python to Java using Chaquopy? The Python dataset is a list of integers (e.g. list = [1, 3, 5, 7...]) with a size of +100,000.

I found that I could return the list to Java as following:

short[] data2 = py.getModule("main").callAttr("rula_timeline").toJava(short[].class);

However, in my Java I need the dataset as an ArrayList. I am new to Java so I don't know how to convert it.

Frederik Petri
  • 451
  • 8
  • 24

1 Answers1

0

Of course there's already a StackOverflow question on how to convert an array to an ArrayList, so I won't repeat that here.

However, if you're dealing with lists of hundreds of thousands of items, then you may have some performance problems when converting from Python to Java. In Chaquopy 8.0.0 and later, this can be fixed by using a NumPy array of the corresponding type, rather than a plain Python list. For example, if you want to convert to a Java short array, then for maximum performance your Python code should return a NumPy int16 array.

mhsmith
  • 6,675
  • 3
  • 41
  • 58