Search code examples
javapythonnumpyjython

Transferring 4D array from Python to Jython


My question is basically the title: I have a number of large numpy arrays that I want to port to a Java application, eventually. The only way I see myself doing this is by first transferring this data to Jython. However, I am not sure how to do this as numpy doesn't exist in Jython.


Solution

  • Well, Python will easily let you serialize your data to files in whatever format you want in 3 lines of code. What format your java application can read from?

    If you don't want to write data to disk, or even can't duplicate the in-memory data to pass to other process one thing to check is cap'n'proto -https://capnproto.org/

    One way of serializing the arrays as json encoded data files is simply:

     import json
     json.dump(myarray.tolist(), open("myfile.json", "wt"))
    

    If you Java side can read json, that is all you need.