-4

I dont understand the following code. when im executing it is giving the value error too many values to unpack

train_data=[data, Label]
print train_data
for data, Label in train_data:
     print data
     print Label


 output 
 [array([[23., 114., 49., ..., 61., 66., 75.,],
        [134., 345., 123., ..., 252., 249., 255.],
        ....
        [123., 97., 45., ..., 33., 234.,132.],
        [76., 98., 54., ..., 243., 211.,187.]], dtypye=float32), 
        array([0,0,1,0,2,1,1,0,0,2,2,2,0,0,0,0,2,0,0,2,2,2,0,2,2,1,1,0])]

 ValueError Traceback(most recent call last)
      1. print train_data
  --->2. for data,Label in train_data
 ValueError: too many values to unpack

please help me to solve this issue.

Vijay Prabakaran
  • 113
  • 1
  • 1
  • 8
  • From the question I;m not sure what you are asking, but I believe your issue is a missing `*` in the for loop. I'm assuming Label is the last value of each row?. Then your for loop should be: `for *data, Label in train_data:` – Nihal Sangeeth Oct 24 '18 at 05:42
  • Instead of `data` it should be `*data` in the for loop. – Nihal Sangeeth Oct 24 '18 at 05:43
  • This error means that you are trying to unpack too many variables in only 2 variables. The thing is the way you are using `train_data=[data, Label]` seems weird to me. It's like you are trying to create tuples of data and their labels but actually putting the whole data array first then the label arrays next to it – Wazaki Oct 24 '18 at 05:45

1 Answers1

2

Since I don't have your data, I can't try to reproduce your problem. However, I would suggest you try the following.

instead of train_data=[data, Label] use zip(list_a, list_b)

Try this and let me know whether it works

Wazaki
  • 899
  • 1
  • 8
  • 22