Issue
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
?
Solution
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.
Answered By - Cesar Lopes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.