White Paper MATLAB® to Python

White Paper

MATLAB? to Python:

A Migration Guide



Copyright ? Enthought, Inc.

-

All Rights Reserved. Use only permitted under license. Copying, sharing, redistributing or other unauthorized use strictly prohibited. All trademarks and registered trademarks are the property of their respective owners. and Simulink are registered trademark of The MathWorks, Inc.

Enthought, Inc. W Cesar Chavez St Suite

Austin TX United States



Version . , September

Contents

Introduction

Why Python Getting Started

Differences Between Python and MATLAB?

Fundamental Data Types Organizing Code in Packages, not Toolboxes Syntax Indexing and Slicing: Why Zero-Based Indexing NumPy Arrays Are Not Matrices Programming Paradigm: Object-Oriented vs. Procedural

How Do I?

Load Data Signal processing Linear algebra Machine learning Statistical Analysis Image Processing and Computer Vision Optimization Natural Language Processing Data Visualization Save Data What Else?

Strategies for Converting to Python

From the Bottom Up: Converting One Function at a Time From the Top Down: Calling Python from MATLAB?

What Next?

Appendix

Code Example: Pro ling Contiguous Array Operations Complete Version of main.py, in Chapter Anti-Patterns

References

Introduction

This document will guide you through your transition from

? to

Python. The first section presents some reasons why you would want to to

do so as well as how to get started quickly by installing Enthought Canopy.

The second section highlights some of the most important di erences

between the two languages, including the fundamental data types; how

code is organized in packages; an overview of the syntax di erences; how

indexing and slicing work; NumPy arrays; and how Python mainly uses an

object-oriented programming paradigm.

The third section is structured around vignettes for common tasks when

doing data analysis or running simulations. The vignettes highlight the

most common packages used for each task, such as loading data, cleaning

and reformatting data, performing analysis or simulation, plotting, and

saving data.

The fourth section introduces two strategies to gradually transition to

Python. Both rely on testing to validate that the new Python code works

the same way (or is broken in the same way!) as your

? code. They

approach the problem by either converting all function directly to Python

or by calling Python from

?. You should use the one that is most

convenient for your project.

Who Is This Guide For This guide is for long time

? users who want

to migrate to Python, either partially or completely. I once was such a

person.

Who Is This Document Not For If you rely heavily on the Simulink? graphical programming environment, you're out of luck. There is no good Simulink? equivalent in the Python ecosystem. If you have very special hardware integration needs, you might be able to find a package that works for you on the Python Package Index, but there is no guarantee that it will be actively maintained or that it will support all the features you need. However, there is nothing stopping you from implementing the features you need and sharing them with the world. Someone, somewhere,

Download Enthought Canopy at https: //store.downloads/. For a good discussion about Simulink? alternatives, I recommend the article Free and commercial alternatives to Simulink on Mike Croucher's blog, Walking Randomly.

? Enthought, Inc.

Accelerate your Python migration with Enthought's Python for Scientists and Engineers training course!

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download