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.
263 questions
10
votes
1
answer
378
views
How to deal with the zombie apocalypse caused by Python ExternalSessions?
I am working on a Mathematica package for knot theory that combines functionality of several other packages. Two notable examples are SnapPy and Regina. Fortunately, both have a rich Python interface ...
7
votes
3
answers
467
views
(discrete) Surface parametrization in Mathematica
In Python there are very easy to use and efficient libraries for surface parametrization (for instance igl). I wonder if in Mathematica we have a ready-made implementation.
The parametrization is ...
0
votes
0
answers
72
views
Robust way to test whether two symbolic expressions equals in python interface of Wolfram script
I have two mathematically equivalent latex strings
...
0
votes
0
answers
87
views
External Python evaluator exists, but trying to register causes process not to start
I am trying to register an external installation of Python 3.13 to be usable through ExternalEvaluate in Mathematica v14. After running
FindExternalEvaluators["Python"], I can see the ...
5
votes
0
answers
165
views
How to speed up value function optimization in simple dynamic programming task (cake-eating problem)
There is a book on dynamic programming. There is an introduciton chapter on simple cake-eating problem.
The model is
$$\max_{\{c_t\}} \sum_{t=0}^\infty \beta^t u(c_t) \quad \text{s.t.} \quad x_{t+1} = ...
2
votes
0
answers
46
views
What is the best way to combine ExternalEvaluate with RemoteRunProcess?
session = StartExternalSession["Python"] starts a python session on the local machine.
...
2
votes
0
answers
76
views
Call Compiled Function in Python
How can I call a function made with Compile in Python, Is it possible to just save it using LibraryGenerateand call the ...
1
vote
1
answer
153
views
Translating Python for loops to Mathematica [closed]
I have the following snippet written in Python that I want to run in Mathematica
...
4
votes
1
answer
243
views
Converting laborious Mathematica expressions into Python source code automatically
I have worked out a (regrettably rather laborious and seemingly irreducible) expression in Mathematica. I'd like to use this expression in a ...
2
votes
0
answers
486
views
Mathematica to Python [closed]
I have very large expressions in Mathematica which I need to convert to python for fast numerical computations. Is there a way to do it automatically. I dont want to type it manually. It will take me ...
0
votes
0
answers
45
views
How to export the given data to be imported by python? [duplicate]
Consider the following data:
...
7
votes
2
answers
625
views
How can I pass a float variable from Python to Wolfram Kernel?
I want to do something like this:
...
3
votes
1
answer
172
views
How to Convert WLSymbolFactory to Python String?
I'm trying to simulate with python and Mathematica, Python need to generate and save some pictures to the directory of current mma notebook, I know the function that ...
0
votes
1
answer
237
views
Export algebraic expression to Python with special functions
I have an enormous algebraic expression in Mathematica that I want to export to Python. The expression per se is not complicated, more like a polynomial, but it contains some special functions defined ...
3
votes
0
answers
75
views
Mathematica call CompiledFunction from Python with Listable and Parrallelization attributes
I have a CompiledFunction e.g. this:
...
1
vote
1
answer
80
views
Using ExternalObjects for python iterators
Iterators are a common pattern in python. A trivial example is:
example = iter(("apple", "banana", "cherry"))
next(example)
(yes, of ...
0
votes
0
answers
109
views
How do you rate Mathematica and Python in terms of numerical computation? [duplicate]
I often hear, in the physics community, that python is faster and overall better than mathematica for numeric calculations. But this seems very subjective since code badly written in one language can ...
0
votes
1
answer
90
views
What is the fastest way to change Python environment?
We can see all registered Python environments through FindExternalEvaluators["Python"].
But the user interface will use the last registered one.
How to ...
1
vote
1
answer
150
views
Removing notebook cache from ExternalEvaluate
Question
While working with Python's ExternalEvaluate the intermediate calculation results with Python are stored in the notebook. (...
2
votes
1
answer
249
views
Python Code to Mathematica for Classical Map of Kicked Top
I am trying to convert this Python code for Classical map of kicked top to Mathematica.
For a single trajectory, I am able to ...
1
vote
0
answers
226
views
Convert a string of Python expression into Mathematica expression within Mathematica
While there are many ways to convert a Mathematica expression into other Languages, I was wondering if there is something reverse for Python. There are some discussions in Python groups, but I am ...
1
vote
1
answer
341
views
Performance of polynomial functions in Mathematica vs Python [closed]
I am trying to compare the performance of Mathematica vs Python for vectorized operations involving polynomials. The data is floatMatrix which has dimensions (...
1
vote
0
answers
71
views
Python external evaluator missing first print
Can you confirm this bug when evaluating Python code in Mathmatica?
Type > select Python by clicking on the icon on the left then paste the following code and ...
0
votes
0
answers
151
views
Where is the Python distribution pre-installed with Wolfram?
I am using the latest version 13.3, does Wolfram comes preinstalled with a python kernel/distribution?
I heard that some of the currently working features like sqlite connectivity uses python code, so ...
0
votes
0
answers
298
views
Mathematica Client Library for Python sometimes can't communicate with Kernel
I have been using the Mathematica client library for Python, but it errors at random some times when running the program, returning:
wolframclient.exception.WolframKernelException: Failed to ...
3
votes
1
answer
266
views
How to get matplotlib-type ticks? [closed]
Consider the following plot, obtained with the Python plotting library matplotlib:
Is it possible to get the plot ticks to have this same style in a Mathematica ...
0
votes
0
answers
151
views
How to pass variables from Python to Mathematica?
I have a Mathematica code that I want to run via Python using subprocess. The Mathematica code contains two variables that I want to pass through Python.
However, when I tried to do that, I always got ...
11
votes
0
answers
382
views
Mathematica 13.3 breaks old socket code
Edit 3: This bug is no longer present in Version 14.1.
It appears to have been fixed in either Version 14.0 or Version 14.1.
Edit 1: A support case with the identification [CASE:5059026] was created.
...
6
votes
1
answer
2k
views
Code for quasi 1D nozzle flows
The quasi-one-dimensional model describing the flow of compressible gas in rocket nozzles is very common. The corresponding equations have a divergent non dimensional form
$ \frac{\partial \mathbf{U}}...
8
votes
3
answers
1k
views
How to pass values to Python?
I would like to pass Mathematica variable values to Python. But I found that it was not that trivial. For example, a typical way would be:
...
4
votes
0
answers
228
views
Using Mathematica ML models in another application
Using Mathematica, I trained and exported some machine learning models with the suggested file extension .wmlf. However, I noticed that these files are stored in HDF5 format. How can I import these ...
5
votes
2
answers
586
views
Is there a built-in equivalent to numpy's fftfreq?
I recently learned that python's numpy package contains a function called fftfreq (documented at numpy.fft.fftfreq) which is ...
2
votes
0
answers
212
views
Convert Wolfram to Python [closed]
Is there any way for python to generate a list and then find a function based on it just like how FindFit works in Wolfram? Preferably I would like the solution to work on Replit or Google Colab. ...
1
vote
0
answers
214
views
How to import specific Python Libraries using External Evaluate
I want to use specific python libraries via the Mathematica frontend. This is possible as follows
...
3
votes
0
answers
248
views
Can Mathematica's Minimize() function be called inside Python code using Python data?
Summary:
I would like to use the Wolfram Client Library for Python to invoke Mathematica's Minimize function directly from within Python, passing to it Python data structures.
Details:
I have a Python ...
1
vote
0
answers
43
views
Python np.gradient in Mathematica [duplicate]
Very quick and dirty question. I'm trying to write a program written in python into mathematica and there is a section that uses the gradient function in the numpty python library, ...
1
vote
0
answers
89
views
What are ExternalLanguage cells good for? [closed]
You can type > at the beginning of a cell (or right click and choose "insert new cell" - "ExternalLanguage") and then you can choose the ...
6
votes
1
answer
271
views
Python compatible fortran form for complex numbers
I am trying to use the Mathematica output of a complicated expression as input for python. As suggested in this answer, the FortranForm of an expression already ...
3
votes
2
answers
491
views
Solving hyperbolic equation with parallelization in python by elucidating Mathematica algorithm [closed]
So! I have what seems like a rather basic hyperbolic equation to be solved written in Mathematica, with an integer input ‘n’, for which I am seeking the First {x,y} Integer solution to satisfy the ...
3
votes
1
answer
657
views
How to run Wolfram language using Wolfram Client Library for Python in Google colab?
How to run the Wolfram language using Wolfram Client Library for Python in Google colab?
3
votes
2
answers
693
views
Use python color scale in mathematica density plot
I have a python code for data analysis, that uses the "seismic" color scale for 2D density plots. However, I also need to do some other plots with Mathematica (because of packages etc), for ...
2
votes
0
answers
147
views
How can we call Mathematica functions from another server using the `wolframscript` Python library?
How can we use the wolframclient Python library to call Mathematica functions when Mathematica is running in an another server?
For example, if we have Mathematica ...
0
votes
0
answers
378
views
How can I call the function NSolve from Mathematica in Python?
I would like to use the NSolve function from Mathematica in a Python code to solve a polynomial system of equations. So my question is, whether there is an option to call this kind of function in a ...
4
votes
1
answer
266
views
WolframClient output convert to Python complex array
I encountered the following issue with WolframClient. I have a my.function file which contains some function that takes some ...
10
votes
1
answer
844
views
How to use Python functions in Mathematica functions in Python notebooks?
I want to plot things with Mathematica, inside an ipynb Python notebook. I can easily plot functions that are expressed in the Wolfram Language, e.g. with
...
0
votes
0
answers
134
views
Error while using External Evaluator (Python)
In the above screenshot, I've shared the installed and registered version of python. However, when I try to use it, it ends up with an error.
...
1
vote
2
answers
896
views
Mathematica `fourier` get different result with python `np.fft` [closed]
In python,I run fft as below:
...
7
votes
2
answers
527
views
Calling a Python class function from ExternalEvaluate
I am attempting to use ExternalEvaluate to use some python packages (ARC) to save me some effort in performing the calculations in Mathematica, and for the most part I think it works as intended.
The ...
2
votes
1
answer
318
views
Wolfram Engine beginner's question: how to Sum?
I really like the idea of the Wolfram Engine, and in particular using it via the python client library. However, I've having trouble understanding the syntax for even simple commands: is there some ...