0

I have a Python script that calculates a few, quite small, NumPy arrays and I have a Java service on a separate machine that needs to use these arrays.

These arrays sometimes need to be recalculated and then used afterwards by the Java service. What is the best way to dump a NumPy array to the disk and load it in Java as float[][]?

I know that I could use JSON to do this (Python script dumps the NumPy array to a JSON file and Java service recovers float[][] from this), but is there any other, "preferred" way?

2 Answers 2

1

You could use HDF5, which is supported by Java and Python, but this is still a hack. Is there some common interface (e.g. DLL, etc.) that you could use to exchange a pointer to the data buffer in RAM?

If that's not possible I'd stick with old school ASCII CSV files instead of using JSON.

Sign up to request clarification or add additional context in comments.

Comments

1

Saving a file to disk to exchange the data between different applications sounds like a hacky approach to me.

Depending on your structure and complexity, I would consider implementing a messaging queue (i.e. redis) or a document database (i.e. mongo or prefered alternative) with respective clients to do the data exchange between the apps.

On the data structure itself, I would choose json or csv for the task. If you need human readability or strict structure, json is your tool. If the data is meant only for the machine to read, csv takes less space to store the same amount of data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.