Home > Mobile >  How to store multiple 2D matrices in Python
How to store multiple 2D matrices in Python

Time:12-01

I want to store 2D matrices in a another list or container.

I have 5 different 2d matrices. Each matrix has a size 36 X 36. I want my output as below,

big_matrix = [ [36 X 36], [36 X 36], [36 X 36], [36 X 36], [36 X 36]]

Kindly guide me.

CodePudding user response:

If you are not restricted to pure python, Id recommend you to use numpy!

f.e.

import numpy as np

2d_matrix = np.ones((36, 36), dtype=int)

CodePudding user response:

you actually dont need to specify the size of your matrix in python. You can start by creating your matrices

matrix1 = [[1,2,3],[4,5,6]]
matrix2 = [[7,8,9],[10,11,12]]
matrix3 = [[13,14,15][16,17,18]]

and append them together

big_matrix = []
big_matrix.append(matrix1)
big_matrix.append(matrix2)
big_matrix.append(matrix3)

If you would like to have a better maintenance for your matrices I recommend looking into numpy matrices.

Dear Yaz

  • Related