Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Python modules in Octave?

Tags:

python

octave

I want to write functions for Octave using Python. Google did not help in finding out whether it was possible to somehow import/include/whatever Python modules in Octave and call them as if they were native .m functions. I looked at Cython, which creates C source code from Python, but it uses Python objects as arguments and return types. Is it possible to use Python modules in Octave?

like image 514
Kaushik Avatar asked Jun 07 '11 09:06

Kaushik


2 Answers

Unfortunately there is no straightforward way to do this.

Yet, it is always possible to run a Python program and parse the output. In fact

You can execute any shell command using the function system (cmd, flag). The second argument is optional. If it is present, the output of the command is returned by system as a string. If it is not supplied, any output from the command is printed, with the standard output filtered through the pager.

For example:

output = system ("python /home/user/some_algoritmh.py", 1)
like image 192
Zaur Nasibov Avatar answered Oct 18 '22 00:10

Zaur Nasibov


There exists a project on Github, pyoctave, which is a C++ extension to Octave and which can call functions of Python modules. You have to compile the extension once to create an oct file and can use this oct file to call Python code.

Code on Github

like image 1
DeStOv Avatar answered Oct 17 '22 23:10

DeStOv