问题:将MATLAB代码转换为Python的工具

我的MS论文中有一堆MATLAB代码,现在我想将其转换为Python(使用numpy / scipy和matplotlib)并作为开源分发。我知道MATLAB与Python科学库之间的相似之处,手动转换它们的时间不会超过两周(前提是我每天都会努力一段时间)。我想知道是否已经有任何工具可以进行转换。

I have a bunch of MATLAB code from my MS thesis which I now want to convert to Python (using numpy/scipy and matplotlib) and distribute as open-source. I know the similarity between MATLAB and Python scientific libraries, and converting them manually will be not more than a fortnight (provided that I work towards it every day for some time). I was wondering if there was already any tool available which can do the conversion.


回答 0

有几种工具可以将Matlab转换为Python代码。

那见过最近的活动只有一个(最后从2018年6月提交)是小号商场中号 ATLab的牛逼Ø P ython编译器(这里也开发:SMOP @ chiselapp)。

其他选项包括:

  • LiberMate:从Matlab转换为Python和SciPy(需要Python 2,最新更新为4年前)。
  • OMPC:Matlab到Python(有点过时)。

同样,对于那些对两种语言之间的接口感兴趣而不是转换的人:

  • pymatlab:从Python进行通信,方法是将数据发送到MATLAB工作区,使用脚本对其进行操作,然后拉回结果数据。
  • Python-Matlab虫洞:支持双向交互。
  • Python-Matlab桥:从Python内部使用Matlab,为iPython提供matlab_magic,以从ipython内部执行普通的matlab代码。
  • PyMat:从Python控制Matlab会话。
  • pymat2:看似被遗弃的PyMat的延续。
  • mlabwrapmlabwrap-purepy:使Matlab看起来像Python库(基于PyMat)。
  • oct2py:从Python内部运行GNU Octave命令。
  • pymex:将Python解释器嵌入到Matlab以及文件交换中
  • matpy:通过各种方式访问​​MATLAB:创建变量,访问.mat文件,直接连接MATLAB引擎(需要安装MATLAB)。
  • MatPy:Python软件包,用于数值线性代数并使用类似于MatLab的界面进行绘图。

顺便说一句,在这里查找其他迁移技巧可能会有所帮助:

另一方面,尽管我一点也不喜欢,但fortran对于可能会觉得有用的人来说,有:

There are several tools for converting Matlab to Python code.

The only one that’s seen recent activity (last commit from June 2018) is Small Matlab to Python compiler (also developed here: SMOP@chiselapp).

Other options include:

  • LiberMate: translate from Matlab to Python and SciPy (Requires Python 2, last update 4 years ago).
  • OMPC: Matlab to Python (a bit outdated).

Also, for those interested in an interface between the two languages and not conversion:

  • pymatlab: communicate from Python by sending data to the MATLAB workspace, operating on them with scripts and pulling back the resulting data.
  • Python-Matlab wormholes: both directions of interaction supported.
  • Python-Matlab bridge: use Matlab from within Python, offers matlab_magic for iPython, to execute normal matlab code from within ipython.
  • PyMat: Control Matlab session from Python.
  • pymat2: continuation of the seemingly abandoned PyMat.
  • mlabwrap, mlabwrap-purepy: make Matlab look like Python library (based on PyMat).
  • oct2py: run GNU Octave commands from within Python.
  • pymex: Embeds the Python Interpreter in Matlab, also on File Exchange.
  • matpy: Access MATLAB in various ways: create variables, access .mat files, direct interface to MATLAB engine (requires MATLAB be installed).
  • MatPy: Python package for numerical linear algebra and plotting with a MatLab-like interface.

Btw might be helpful to look here for other migration tips:

On a different note, though I’m not a fortran fan at all, for people who might find it useful there is:


回答 1

还有oct2py可以在python中调用.m文件

https://pypi.python.org/pypi/oct2py

它需要GNU Octave,它与MATLAB高度兼容。

https://www.gnu.org/software/octave/

There’s also oct2py which can call .m files within python

https://pypi.python.org/pypi/oct2py

It requires GNU Octave, which is highly compatible with MATLAB.

https://www.gnu.org/software/octave/


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。