Group Abstract Group Abstract

Message Boards Message Boards

How to pass data to Python in Mathematica?

I hope to use the Python package to assist in data calculations. Can I pass data to Python in Mathematica? I have tried to save the data as a file and then read it with NumPy (this is feasible)~~ But I still hope to be able to directly transfer data to improve efficiency!

POSTED BY: Tsai Ming-Chou
5 Replies
POSTED BY: Tsai Ming-Chou
Posted 4 years ago
POSTED BY: Alec Graves
Posted 4 years ago

The problem is that data in Python is formatted as a WL List, not a Python array. I am not sure what is the best way to do the conversion. You could try

testArray = ExportString[test, "PythonExpression"]

and convert testArray from string to Python array using eval. There must be a better way.

You mentioned earlier that writing to a file in WL and reading it from Python works but you were looking for a more efficient method. How many geo locations are there in your real data?

POSTED BY: Rohit Namjoshi

Thank you for your suggestion~~ I tried it according to my understanding~ But received the wrong message ("WLSymbolFactory object is not subscriptable") Could you please give more suggestions?

POSTED BY: Tsai Ming-Chou
Posted 4 years ago

Hi Ming-Chou,

Assuming that the data is generated using some Wolfram Language code, it might be easier to call it from Python. Take a look at the Wolfram Client Library for Python.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard