-6

dataset[i][j] is a 100x30 matrix.

And I want to convert to a list using list comprehension.

I tried train_dataset = [dataset[i][j] for i,j in [range(30), range(100)]]

but there was an error : ValueError: too many values to unpack (expected 2)

How could I assign the conversion, so len(train_dataset)=3000 ?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
mario119
  • 343
  • 3
  • 14

1 Answers1

1

If I got this right, dataset is a matrix, with size 100x30, 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.

Cesar Lopes
  • 373
  • 1
  • 10