Skip to main content
40 votes
Accepted

Exchanging numpy arrays between Python and Mathematica?

You can use the binary format to speed up the process: python side import numpy as np array = np.random.rand(100000000); array.astype('float32').tofile('np.dat') ...
xslittlegrass's user avatar
35 votes

How can I use the Python library networkx from Mathematica?

Mathematica 12.0 brings two new features that make this easier to do than it was before: ExternalFunction Wolfram Client for Python Below we implement a function <...
Szabolcs's user avatar
  • 236k
32 votes

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

General remarks Before giving several (biased) answers to the question As a developer I'd like to ask if there any other significant advantages to Mathematica - are there any areas where ...
Anton Antonov's user avatar
19 votes
Accepted

FindExternalEvaluators["Python"] gives me an uninstalled version of Python

Update: As of version 12, one should use FindExternalEvaluators["Python", "ResetCache" -> True] To turn my comment into an answer, ...
ilian's user avatar
  • 25.5k
19 votes
Accepted

How can I use Python's SciPy and NumPy functions in Mathematica to find the minimum of a function?

I believe you're not in the correct direction, optimizing your Mathematica code should be more practical and easier. (You've already learned the numeric capability of Mathematica under your previous ...
xzczd's user avatar
  • 67.1k
17 votes

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

I actually failed miserably in a Kaggle contest using Mathematica Enterprise. I tested every single variation of Classify and Predict and even combinations of the two. I also tested Microsoft ML ...
ArtificialBrilliance's user avatar
16 votes
Accepted

Is there a way to run Python from within Mathematica?

Since 11.2 Mathematica has supported ExternalEvaluate and since 11.3 this functionality has been conveniently available simply by beginning an input cell with ...
orome's user avatar
  • 12.9k
16 votes

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

Do not underestimate Mathematica's notebook. The fact that your code looks like math (you can make it be in fractions with the exponents up, etc.) can make it much easier to work with. This, and the ...
Chris Rackauckas's user avatar
16 votes

Exchanging numpy arrays between Python and Mathematica?

Here is a template to read a numpy binary ".npy" file created simply by numpy.save(filename,array) this file format has the array structure encoded as a python ...
george2079's user avatar
16 votes

ExternalEvaluate for Python fails with Import::nopythonevals

To get this out of the way: I believe the Import::nopythonevals message will be issued by Import[..., "PythonExpression"] if ...
Szabolcs's user avatar
  • 236k
16 votes
Accepted

How to import python pickle *.pkl?

I found some tools which can translate python objects to wolfram expressions. https://github.com/WolframResearch/WolframClientForPython ...
Aster's user avatar
  • 3,846
16 votes

List comprehensions in Mathematica?

IMO, Mathematica's functional operators more than cover the use cases for list comprehensions in Python. There are a couple of different list comprehension syntaxes which are covered by a couple of ...
C. E.'s user avatar
  • 70.9k
15 votes
Accepted

Mathematica + Pythonika on the Raspberry pi

I was able to do it. I'll post what I did in case somebody else needs it. So far it works really nice. Just follow the instructions from the repository, and modify the ...
elbOlita's user avatar
  • 1,681
15 votes

Prepare Mathematica output to be parsed in Python

Here is a Module I prepared to convert most expressions (including lists) to Numpy. It may not be the most elegant solution, but it works pretty well. Below I also include some examples. ...
Gustavo Wiederhecker's user avatar
15 votes

Convert python Code To Mathematica?

I do not think there is general way to convert large chunk of code from Python to Mathematica (such as complete functions). But for individual expressions you could try this do it via Latex. In ...
Nasser's user avatar
  • 147k
14 votes
Accepted

mathematica's equivalent of python list functionnality

Yeah, you can do destructuring assignments: ...
Pillsy's user avatar
  • 18.6k
14 votes

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

.fits method One possible way is to use the .fits format... Export["~/Dropbox/tensor.fits", tensor] ...
Conor Cosnett's user avatar
14 votes

How to display images inside Mathematica with matplotlib

Seems to be able to embed images by converting to png. ...
Aster's user avatar
  • 3,846
14 votes

How can I use Python's SciPy and NumPy functions in Mathematica to find the minimum of a function?

The first solution will use socket to connect python and Mathematica. We'll set up a server that returns the result of the function that has been defined in ...
Ben Izd's user avatar
  • 9,484
13 votes

Difference between Python and Mathematica for Newton's Algorithm

The previous answers have already hinted at what FindRoot[] does. In particular, Mathematica implements a "safe" version of Newton-Raphson with support for damping ...
J. M.'s missing motivation's user avatar
13 votes

How to read .npy file in Mathematica?

I would suggest reading it with numpy and not Mathematica. It seems to me that this is not an exchange format. It is a format meant to be used only by numpy. Mathematica 12.0 has significantly ...
Szabolcs's user avatar
  • 236k
13 votes
Accepted

How to export a notebook to Jupyter?

The main point is that Jupyter is a flat structure, but the Notebook is a nested structure. It took me a long time to fully ...
Aster's user avatar
  • 3,846
12 votes

Run Python with package NumPy in Mathematica

Starting in version 11.2 you may use ExternalEvaluate to run Python from Mathematica. See the Configure Python for ExternalEvaluate tutorial for setup. ...
Edmund's user avatar
  • 42.4k
12 votes
Accepted

Equivalent of "for X in [list]" or "foreach"

There are several constructs you can use. The one that comes closest to the foreach of other languages is ...
12 votes
Accepted

How to open a Python interpreter input cell?

Type > at the start of a cell (or when between cells). This is documented in an example on ref/ExternalEvaluate (last Basic Example). I'm a bit suprised it's not in the details section. It probably ...
Itai Seggev's user avatar
  • 14.2k
11 votes
Accepted

Translating python code to mathematica code

This question demonstrates one of the best things I love about Mathematica; mathematical notation as code. Using Esc+pw+Esc and Ctrl+Enter you can enter the function in ...
Edmund's user avatar
  • 42.4k
11 votes
Accepted

Corresponding built-in types for Python

I think you can find what you're looking for here:
ktm's user avatar
  • 4,292
11 votes

How to add new python type translation to ExternalEvaluate?

A class who inherits the WLSerializable class and overrides the to_wl method can be automatically converted. ...
Aster's user avatar
  • 3,846
11 votes

How to set default version for an external language code cell?

A ResourceFunction called SetLanguageCellSession gives a complete solution for managing external language sessions in Python, Julia, R, etc. Basic example: This ...
M.R.'s user avatar
  • 31.6k

Only top scored, non community-wiki answers of a minimum length are eligible