O'Reilly logo

NumPy Cookbook - Second Edition by Ivan Idris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exchanging data with MATLAB and Octave

MATLAB and its open source alternative, Octave, are popular mathematical applications. The scipy.io package has the savemat() function, which allows you to store NumPy arrays in a .mat file as a value of a Python dictionary.

Getting ready

Installing MATLAB or Octave is beyond the scope of this book. The Octave website has some pointers for installing at http://www.gnu.org/software/octave/download.html. Check out the See also section of this recipe, for instructions on installing SciPy, if necessary.

How to do it...

The complete code for this recipe is in the octave.py file in this book's code bundle:

import numpy as np
import scipy.io

a = np.arange(7)

scipy.io.savemat("a.mat", {"array": a})

Once you have installed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required