0

I have a bunch of different matrices of different size stored on disk. I need to process them in python in a fast way so I loaded every matrix into memory and stored them in a python list. I want to select a subset of these list entries via a vector of row indices (equivalent to selecting cells in a cell array in Matlab) is that possible in python?

A Matlab example would look like this:

allData = cell(100,1); % This cell array contains my different matrices of variable sizes
rowIndices = randi(100,10,1);

selectedData = allData(rowIndices,1);

How can I do the same in python?

allData # In python this is a list of "numpy.ndarray"s
rowIndices = random.sample(range(1, numRows), batch_size)
batch_data = allData[rowIndices]

doesn't work

2 Answers 2

1

A simple approach would be to use a list comprehension:

batch_data = [allData[i] for i in rowIndices]
Sign up to request clarification or add additional context in comments.

Comments

1

Consider using NumPy matrix. It looks like its take() method could be helpful in this case.

Comments

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.