1

I have a Matlab cell array, each of whose cells contains an N x M matrix. The value of M varies across cells.

What would be an efficient way to represent this type of a structure in Python using numpy or any standard Python data-structure?

2
  • I think the easiest solution would be a dictionnary d={key: numpy.array([N,M]) ). You can iterate over it and access elements by key, however you lose the possibility to access by position. Commented May 22, 2013 at 10:49
  • 1
    A list is probably the closest thing in Python to a Matlab cell array. It can hold mixed types, like matrices of different sizes. (See Shai's answer) Commented May 22, 2013 at 11:02

1 Answer 1

5

Have you considered a list of numpy.arrays?

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I think this might be the simplest thing to do for now. The dictionary idea isn't the best, because I would be accessing the arrays by their position in the list. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.