1

I'm working with images and want to create a list of lists of arrays. For example, a list with 5 rows, where each row has a variable number of images (3x200x100) stored in them ranging from 2 images to 10 images.

I've ruled out numpy and concatenation since they need the matrix to be uniform. I've tried appending one list to another, but that just gives me a long row of them when what I want is another row to be added after the prior row.

I was thinking that either a list or a dictionary would be the way to go since what I'm using to populate my list of lists is a dictionary, but I'm unable to figure out how to structure the lists so that it's correct to my above specifications instead of just a super long list. Is there any way for me to initialize a list so that only the row number gets specified and I can dynamically change the column number per row? If not, is there a different data structure I should be looking at?

1
  • If you create a list where each element is a list, you get a list of lists, and each sublist can have its own size. Commented Aug 1, 2016 at 18:57

1 Answer 1

1

How about something like this?

row1 = [1,2,3,4,5,6]
row2 = [1,2,3]

matrix = [row1, row2]

row3 = [1,2,4,5,6,7,8,9]
matrix.append(row3)
Sign up to request clarification or add additional context in comments.

2 Comments

Since it isn't possible to append to a list that hasn't been initialized, is there any way of not specifying what goes in "matrix"?
@user6664585 Just initialize it to an empty list. matrix = []

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.