Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy equivalent of MATLAB's cell array

I want to create a MATLAB-like cell array in Numpy. How can I accomplish this?

like image 537
vernomcrp Avatar asked Nov 19 '09 07:11

vernomcrp


People also ask

What is a cell array in Python?

A cell array is a data type with indexed data containers called cells, where each cell can contain any type of data. Cell arrays commonly contain either lists of text, combinations of text and numbers, or numeric arrays of different sizes.

Is NumPy like MATLAB?

NumPy (Numerical Python)NumPy arrays are the equivalent to the basic array data structure in MATLAB. With NumPy arrays, you can do things like inner and outer products, transposition, and element-wise operations.

Is NumPy faster than Matlab?

Speaking about pure Python with NumPy, the Matlab is definitely faster.


1 Answers

Matlab cell arrays are most similar to Python lists, since they can hold any object - but scipy.io.loadmat imports them as numpy object arrays - which is an array with dtype=object.

To be honest though you are just as well off using Python lists - if you are holding general objects you will loose almost all of the advantages of numpy arrays (which are designed to hold a sequence of values which each take the same amount of memory).

like image 88
robince Avatar answered Sep 19 '22 19:09

robince