Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
2answers
119 views

How to turn a Python array into Mathematica List?

I am running a = RunProcess[$SystemShell, "StandardOutput", "python2 fit.py"] which returns "[ 0.04044647 0.75243326 -0.42992283]\n[ 0.04163976 0.15076435 ...
6
votes
2answers
155 views

How to read .npy file in Mathematica?

I have a .npy file which is created by numpy of Python as below:- ...
20
votes
1answer
831 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.
1
vote
0answers
53 views

Difficulty with ExternalEvaluate

I am trying to import a Python function or execute a Python script from inside Mathematica, but the ExternalEvaluate command drives me nuts. I proceed cautiously ...
1
vote
0answers
21 views

Connect to running external session?

Is there some way to connect to an already running process in the same way that StartExternalSession starts a process?
1
vote
0answers
37 views

How can I efficiently call an external Python script that needs to run continuously?

I am writing a Mathematica program that tries to run 100+ Python programs, via StartProcess[], continuously. It seems to work when I run < 100 programs, but, at ...
1
vote
0answers
71 views

Can't register python in ExternalEvaluate

I had Anaconda 3 installed on my system and python registered with the following link: RegisterExternalEvaluator["Python","C:\\Users\\atfai\\Anaconda3\\python.exe"]...
1
vote
0answers
124 views

Mathematica Reduce function in Sympy [closed]

I am now using Mathematica to compare two big expressions with Reduce function. However, since these two expressions are very complicated, I can not get an answer ...
0
votes
0answers
47 views

How to install only Wolfram Kernel and register to a MathLM Server?

I have access to a MathLM server and the Mathematica 11.3 install files. Is there a command line option for the install that will only install the Wolfram Kernel and not the Mathematica front-end? ...
3
votes
1answer
111 views

Is there any way that convert entire mathematica code to java or python?

I am novice to Mathematica. I want to convert Mathematica code from my textbook to Java or Python to trace coding.
0
votes
1answer
48 views

Convert string representation of matrix to matrix

I have a Python script which generates and outputs Mathematica matrices. I use RunProcess to run my Python script and I extract the StandardOutput which is the Mathematica matrix as a string. What I ...
1
vote
0answers
85 views
1
vote
0answers
42 views

ExternalEvaluate Python print is printing an extra empty cell with newline

When using print command in ExternalEvaluate["Python","print(1+1)"] or ExternalLanguage cell using >, there is always an extra ...
0
votes
0answers
25 views

Python Syntax highlighting in external code cell [duplicate]

Mathematica has python external code cells and they execute using the available python kernel on the machine but the code cells don't have python syntax highlighting which is necessary for ...
1
vote
1answer
36 views

Using ExternalEvaluate within ParallelDo

I have had great success using Python in Mathematica (for some computations for which there are very well optimised Python packages but not for Mathematica). I have some Mathematica functions that are ...
2
votes
1answer
176 views

How to register Anaconda3(Python3.7) as external evaluator enviroment?

I have installed Anaconda3 (version 5.3.1 for Windows with Python 3.7, 64-bit) as the Python working enviroment, but when trying to register it as an external evaluator, it ...
5
votes
2answers
119 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]) ...
1
vote
1answer
92 views

Python module attributes not recognised in ExternalEvaluate

I have Python installed and running properly. I have a file called test.py with contents c = 5 When I go to the file's ...
1
vote
1answer
128 views

Problem importing from HDF5

I'm trying to import an item from a valid HDF5 file, but I get this error: I can read the metadata, but cannot import the actual tensor dataset: And yet it's not an issue with the file's data - as ...
9
votes
2answers
262 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 ...
10
votes
2answers
460 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? ...
7
votes
2answers
169 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?
9
votes
1answer
129 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 ...
5
votes
0answers
39 views

Dynamically access variables in external session?

I tried to get a value from a python session to show up in a dynamic cell: First run: ...
3
votes
0answers
50 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?
3
votes
1answer
34 views

How to delete certain item(s) returned by FindExternalEvaluators[]? [duplicate]

I have tried UnregisterExternalEvaluator only to find that the item's state "Registered", changed from True to ...
4
votes
1answer
89 views

How to apply the layer of sigmoid function in neural network?

I saw an article How to build a simple neural network in 9 lines of Python code and want to reconstruct the result in Mathematica. I tried the below codes:- ...
3
votes
0answers
129 views

Using Numdifftools with ExternalEvaluate to calculate the Hessian

I need to compute numerically the Hessian of a numerical (scalar) function. Mathematica does not have a numerical Hessian routine (funny thing..) and so I am using this implementation. However, though ...
4
votes
0answers
135 views

Use conda env for ExternalLanguage cell?

I really like the new 'ExternalLanguage' cell in v11.3. Is there a way to tell the cell to use a specific conda environment, either as default or for a specific input cell? Mathematica can find ...
6
votes
1answer
120 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 ...
1
vote
1answer
198 views

RunProcess works but not StartExternalSession

I'm using MMA 11.2 on Ubuntu 16.10. Any reason why RunProcess[{"python", "myscript.py"}] works, while ...
5
votes
0answers
216 views

connect to Python kernel started by Jupyter

As Mathematica has the interoperability with Python since ver. 11.2, is it possible to connect the Python kernels started by Jupyter from Mathematica? Can someone provide a pathway for doing that? ...
9
votes
1answer
236 views

Corresponding built-in types for Python

Where can I find the correspondence of built-in types between Mathematica and Python?
4
votes
3answers
493 views

Difference between Python and Mathematica for Newton's Algorithm [closed]

I was about to study the roots of the function defined below, using Newton's Method: 9 Exp[-x] Sin[2 π x] - 0.0015 For initial values, I have: ...
3
votes
0answers
115 views

`ExternalEvaluate` for NumPy: passing numpy arrays

As ExternalEvaluate for python has been introduced recently in V11.2, what is the best practice for passing data between Mathematica and NumPy? As by default, the ...
2
votes
0answers
153 views

Mathematica style plotting in Python? [duplicate]

This question has two related parts. I recently started using more python because it is easier to setup remote machines (and cheaper). But I really miss Mathematica's plotting capabilities and syntax. ...
7
votes
0answers
115 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 ...
20
votes
1answer
650 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 ...
4
votes
1answer
165 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
896 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: ...
4
votes
3answers
743 views

run python with package numpy in mathematica

For example, if I have a python script called simple.py contains as simple as a=1 print(a) then ...
1
vote
0answers
75 views

possibility of using `f2py` for interoperability with Fortran

Although interoperability with Fortran could be realised by using LibraryLink (e.g., Linking FORTRAN with Librarylink), the approach is not so straight forward, in ...
4
votes
1answer
515 views

Problem calling Python scripts from Mathematica

so I'm running into a strange problem using Import[] to import the output of a python 3.6 script. I have a script my_script.py ...
0
votes
2answers
547 views

Create smooth colour map from given array for ListPlot3D

I am trying to find the Mathematica equivalent for Python Matplotlib's cmap option, to be used with ListPlot3D[]. Here is the ...
27
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 ...
7
votes
1answer
387 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. ...
3
votes
1answer
586 views

Python/Numpy array manipulation in Mathematica syntax

As a python programmer, numpy tools usually come to my mind if I want to manipulate arrays (list, matrices, ...). Is there any reference (e.g., dictionary) of how to translate numpy syntax to ...
7
votes
4answers
547 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: ...
5
votes
2answers
494 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 ...