Questions tagged [python]

Questions about interfacing with, or features inspired or demonstrated by Python--a programming language featuring a dynamic type system, automatic memory management, and a comprehensive standard library.

Filter by
Sorted by
Tagged with
66
votes
8answers
11k views

What are the Wolfram Language's relative strengths for machine learning?

I see a low use of Mathematica in Kaggle competitions. Why would one use the Wolfram Language versus R, Python, or Julia for machine learning? Besides prettier plots and the Manipulate function, ...
64
votes
3answers
5k views

Python-style plots in Mathematica

I love making plots in Mathematica. And I love to spend a lot of time making high-quality plots that maximize readability and aesthetics. For most cases, Mathematica can make very beautiful images, ...
64
votes
6answers
27k views

How to use Mathematica functions in Python programs?

I'd like to know how can I call Mathematica functions from Python. I appreciate a example, for example, using the Mathematica function Prime. I had search about MathLink but how to use it in Python ...
55
votes
6answers
9k views

Is there a way to run Python from within Mathematica?

I know there is some support for running Mathematica from Python, but is there any way to do the reverse. For example, to import some Python classes and use them in Mathematica?
38
votes
3answers
19k views

Mathematica vs. Python - how does Mathematica compare to Python's scientific computing suite?

Python's family of packages for scientific computing has matured rapidly. I can pretty much replicate all of Mathematica's functionalities, but with production level and open-source code using the ...
35
votes
2answers
3k views

Is there a built-in equivalent to Python's enumerate?

Python's built-in function enumerate takes an iterable over $(a_0, a_1, \dots )$ as argument and returns an iterable over the sequence of pairs $((0, a_0), (1, a_1),...
32
votes
1answer
5k views

Numerical integration — Mathematica vs Python (w/ Scipy) performance

I'm about to tackle a problem that involves a lot of (multi-dimensional) numerical integrations and also subsequent optimizations, and so I want to make sure at least the integration step is as fast ...
32
votes
1answer
2k views

How does Dataset compare to DataFrame in pandas?

Pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data. Just like ...
31
votes
3answers
2k views

Calling IronPython code from Mathematica

I'd like to call some IronPython code from Mathematica using .NET/Link. The problem is that the code lives in .py files, yet from Mathematica I can only load .NET assemblies which are DLLs. So it ...
29
votes
2answers
3k views

Exchanging numpy arrays between Python and Mathematica?

I've been using np.savetxt(location, result, delimiter=',') in Python followed by Import[location,"CSV"] in Mathematica. Some of ...
21
votes
1answer
1k views

How can I use the Python library networkx from Mathematica?

Is there an easy way to access the Python library networkx from Mathematica? The improvements to ExternalEvaluate in Mathematica 12.0 should make this feasible.
20
votes
1answer
804 views

ExternalEvaluate for Python fails with Import::nopythonevals

I tried using ExternalEvaluate on OS X with Anaconda Python, and every ExternalEvaluate call failed with the ...
19
votes
2answers
4k views

Prepare mathematica output to be parsed in Python

I have Mathematica output that I would like to parse in python so I can generate equivalent expressions. So suppose I have the following: ...
18
votes
5answers
3k views

List comprehension in Mathematica

Python supports a concept called "list comprehensions". Following is sample example (written in Python syntax) ...
17
votes
1answer
421 views

How to connect to an already running interactive Python session?

As Mathematica has the interoperability with Python since M11.2, with major improvements in M12.0, is it possible to connect to already running interactive Python sessions? For example, can we connect ...
15
votes
1answer
2k views

Any solution to transfer data between Python and Mathematica

I think Mathematica handles .mat file not very well, python is pretty good at this kind of jobs. In this site, there are plenty of question related to calling Mathematica from Python, or calling ...
14
votes
1answer
822 views

Mathematica + Pythonika on the Raspberry pi

Due to the high availability of python code for the rpi, I'm trying to call python functions from Mathematica. I know that pythonika works well on OS X, but I can't compile it on the Raspberry pi. ...
12
votes
2answers
548 views

Is there any PythonForm ? to automate Sin[] to math.sin()? [duplicate]

Sin[] does not exist in Python and while I can do FortranForm and similar things, I do not know of any ...
10
votes
1answer
2k views

Output from Wolfram language in Python

I have a Python program which will run a script in the Wolfram language and then return to the main program. Is it possible to return values/variables to the main program? This is the code in Python ...
10
votes
1answer
764 views

How to get Python bindings to work on the Raspberry Pi

There are several examples on this site on how to call Mathematica from Python. You can: install the bindings that come with Mathematica; or call a script as a subprocess from within Python; or ...
10
votes
2answers
487 views

Mathematica equivalent of NumPy broadcast addition for large arrays [duplicate]

What is the Mathematica equivalent of the following Python code with the vectors' broadcast addition? ...
10
votes
1answer
192 views

How to display images inside Mathematica with matplotlib

How to display images inside Mathematica with matplotlib. A new window is generated by default, but is it possible to display the picture directly in the notebook? Like this: related: How to ...
9
votes
2answers
11k views

Convert mathematica math expression form to python math expression?

I obtain a raw input form of: ...
9
votes
1answer
245 views

Corresponding built-in types for Python

Where can I find the correspondence of built-in types between Mathematica and Python?
9
votes
2answers
1k views

How to create a function like in Python

I want to call a function that would perform a function rather than assigning an expression to them. I.e. ...
9
votes
1answer
158 views

How to display images and plots from ExternalEvaluator?

I have a conda python 3.6 environment registered as the default ExternalEvaluator with numpy, matplotlib, cv2, and PIL installed: I'd like to show images and plot ...
9
votes
0answers
888 views

How to write markdown with Mathematica? [duplicate]

Usually I typeset with Latex and Compute with Mathematica and then copy the outputs as Latex code and insert them in Latex, so I have to switch between Latex and Mathematica frequently. Thanks to the ...
8
votes
2answers
509 views

How to import python pickle *.pkl?

I find some ELMo-models on github. I want to use the Simplified-Chinese version: http://pbmpb9h15.bkt.gdipper.com/zhs.model.tar.xz But these files were saved as python pickles. I want to import ...
8
votes
2answers
121 views

How to add new python type translation to ExternalEvaluate?

Seems like Mathematica can only import basic types (lists, numpy objects, etc). Is there a way to tell Mathematica how to understand arbitrary python objects?
7
votes
4answers
626 views

Python's “pop” equivalent in Mathematica

I will like to know if there is an equivalent to python's pop method, here is how it's done in Python: ...
7
votes
1answer
417 views

mathematica's equivalent of python list functionnality

In Python there is a a compact syntax for creating variables that refer to the various list elements. ...
7
votes
2answers
508 views

How to read .npy file in Mathematica?

I have a .npy file which is created by numpy of Python as below:- ...
7
votes
2answers
259 views

Control a Mathematica kernel from the front-end and from python

I'd like to be able to start and control a Mathematica kernel/front-end from python and be able to evaluate things in a notebook and query results on the python side too. Is this possible?
7
votes
0answers
126 views

How to pass in-memory images through ExternalEvaluate?

Version 11.2 has a new import/export format PythonExpression. Unfortunately, it doesn't work out-of-the-box with images: And using the ImageData directly is too slow: Anyhow, I have some image ...
6
votes
2answers
625 views

Export a 3D array from Mathematica and import it in python as a numpy array

In ...
6
votes
1answer
221 views

How to open a Python interpreter input cell?

Something weird just happened to me: I mis-typed a keyboard shortcut, hitting the wrong keys, and a new notebook opened up with a Python prompt! Just for grins, I tried entering some simple Python ...
6
votes
2answers
2k views

How to export an output matrix obtained in mathematica to a matrix in python with the correct format?

I have a large sparse matrix as the output and I want to save the output and open it as a matrix in python. The output is a 6000 x 6000 matrix and I don't know how to make changes to the file such ...
6
votes
1answer
162 views

FindExternalEvaluators[“Python”] gives me an uninstalled version of Python

Long time ago, I have two versions of python installed in my pc, and I registered them all in mathematica. Later I uninstalled one of them, but ...
6
votes
0answers
86 views

Pass Numpy array to Compiled Code (Wolfram Engine, Wolfram Client, Python)

What List-like structures in Python can Wolfram Client handle and how can support for new structures be added? In this answer I describe how to execute from Python, code in a Mathematica package that ...
6
votes
0answers
144 views

Export ImageCases to Python?

I’d like a tutorial on how to export a bounding box detector network to mxnet, (for bonus points: convert to Tensorflow), and then get it running correctly in python! Some related questions exist for ...
5
votes
4answers
6k views

Mathematica's equivalent to the Python's Zip command in List-comprehension? [closed]

What is Mathematica's equivalent to Python's ZIP command? Is this called nesting? It means iterating over sub-sets of values like the below example. How can I do it in Mathematica? Example in Python ...
5
votes
2answers
571 views

Convert Python math expression form (Sin and Cos) to Python math expression?

I have a really big symbolic output from Python, and it contains Sin and Cos. Now I want to solve it using Mathematica, but the ...
5
votes
2answers
201 views

Using local variables in ExternalEvaluate Python

I am sure that I am missing something here, I have some larger matrices and Mathematica takes too long to compute the eigenvalues and vectors (using Eigensystem[m]) ...
5
votes
3answers
3k views

How to convert a Mathematica list in a Python list?

I was wondering if you know, how to save a Mathematica list (variable) such that it can be read later in Python. In order words, how to save a variable ...
5
votes
1answer
1k views

Equivalent of “for X in [list]” or “foreach”

In Python, we can evaluate an expression over specific values of x in a list. Example: ...
5
votes
2answers
461 views

Pasting external PDF vector graphics without losing ability to export them

Update: Problem persists in version 10.2 on Mac OS X 10.9.5 As in previous versions, Mathematica 9 on Mac OS X (10.7.5 here) still has a problem with pasted PDF ...
5
votes
1answer
64 views

ExternalEvaluate[pySys, pyCmd] evaluates to Failure[…]

ExternalEvaluate[pySys, pyCmd] evaluates to Failure[...] every time pyCmd contains some ...
5
votes
1answer
2k views

How to continuously run a Python script

I am running this script: script = Import["!python C:\\...python script", "String"]; but I need to run it a few times as it outputs data I need. I run it every ...
5
votes
1answer
214 views

Using virtualenv and ExternalEvaluate

When doing development work with python, it's often recommended that one use virtualenv. It provides an environment separate from one's standard python evaluator. Now that 11.2 has support for simple ...
5
votes
1answer
124 views

How to execute an existing notebook with Wolfram Engine?

[My related question: mwe-for-compiling-functions-into-standalone-dll-and-calling-them-in-python - here I am exploring an alternative] I have downloaded, installed and activated the wolfram engine (...