[Solved] How to convert a matrix to a list using List Comprehension [duplicate]


If I got this right, dataset is a matrix, with size 100×30, and you are trying to get a list from it?

If this is the case, you can do:

dataset = [[x for x in range(30)] for j in range(100)]
train_dataset = [dataset[i][j] for i in range(100) for j in range(30)]

print(train_dataset)
print(len(train_dataset))

dataset will be:

[0, ..., 29]
[0, ..., 29]
    x100
[0, ..., 29]

and your output will be:

[0, ..., 29, 0, ..., 29... x100]

resulting an array of size 3000.

solved How to convert a matrix to a list using List Comprehension [duplicate]