I'm trying to do 3 slices from a list of vectors from a txt file, with 2 columns, using conditions to separate the RGB.
But when I run the program the following error appears: "'float' object is not iterable". Can anyone help me?
#File opening
arq = open('arquivo.txt','r')
lines = arq.readlines()
arq.close()
vetor_x = []
vetor_y = []
lista_geral = []
for line in lines:
line = line.replace('\n','')
line = line.strip()
line = line.replace(',','.')
line = line.split('\t')
if(len(line) == 2):
X = line[0]
Y = line[1]
vetor_x.append(float(X))
vetor_y.append(float(Y))
lista_geral.append([X,Y])
#Conditions
B = 0
G = 0
R = 0
for i in range(0,len(vetor_x)):
if vetor_x[i] <= 500:
vetor_xB[B] = list(vetor_x[i])
vetor_yB[B] = list(vetor_y[i])
B += 1
elif vetor_x[i] <= 600:
vetor_xG[G] = list(vetor_x[i])
vetor_yG[G] = list(vetor_y[i])
G += 1
elif vetor_x[i] <= 700:
vetor_xR[R] = list(vetor_x[i])
vetor_yR[R] = list(vetor_y[i])
R += 1
print('####### vetor_xB #######')
print(vetor_xB)
print('####### vetor_yB #######')
print(vetor_yB)
print('####### vetor_xG #######')
print(vetor_xG)
print('####### vetor_yG #######')
print(vetor_yG)
print('####### vetor_xR #######')
print(vetor_xR)
print('####### vetor_yR #######')
print(vetor_yR)
However, when I try to run it, this causes this error:
Traceback (most recent call last):
File "teste4.py", line 30, in <module>
vetor_xB[B] = list(vetor_x[i])
TypeError: 'float' object is not iterable
Please help me!
vetor_xB[B] = list(vetor_x[i])you are trying to typecast a single value ofvetor_x. Apparently its a float.