2

In Matlab, there is something called struct, which allow the user to have a dynamic set of matrices.

I'm basically looking for a function that allows me to index over dynamic matrices that have different sizes.

Example: (with 3 matrices)

  • Matrix 1: 3x2
  • Matrix 2: 2x2
  • Matrix 3: 2x1

Basically I want to store the 3 matrices on the same variable. To called them by their index number afterward (i.e. Matrix[1], Matrx[2]). Conventional python arrays do not allow for arrays with different dimensions to be stacked.

I was looking into creating classes, but maybe someone her has a better alternative to this.

Thanks

2 Answers 2

7

Just use a tuple or list.

A tuple matrices = tuple(matrix1, matrix2, matrix3) will be slightly more efficient;

A list matrices = [matrix1, matrix2, matrix3] is more flexible as you can matrix.append(matrix4).

Either way you can access them as matrices[0] or for matrix in matricies: pass # do stuff.

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

Comments

0

Put those arrays into a list.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.