PythonTypeError: 'float' object is not iterable












2















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?



#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_xB)
print('####### vetor_xG #######')
print(vetor_xG)
print('####### vetor_yG #######')
print(vetor_yG)
print('####### vetor_xR #######')
print(vetor_xR)
print('####### vetor_yR #######')
print(vetor_yR)


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!










share|improve this question

























  • what is your vector_xB? Looks like it's a floating point.

    – Kevin Fang
    Jan 2 at 6:18













  • @KevinFang Is a list of values from the first column within the range> = 500

    – Fulana
    Jan 2 at 6:21











  • vetor_x.append(float(X)) why into float?

    – DirtyBit
    Jan 2 at 6:26











  • @user5173426 Because they are not integers

    – Fulana
    Jan 2 at 6:30











  • @Fulana I mean, what's it before this block of code, how do you define and initialize it.

    – Kevin Fang
    Jan 2 at 6:46
















2















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?



#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_xB)
print('####### vetor_xG #######')
print(vetor_xG)
print('####### vetor_yG #######')
print(vetor_yG)
print('####### vetor_xR #######')
print(vetor_xR)
print('####### vetor_yR #######')
print(vetor_yR)


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!










share|improve this question

























  • what is your vector_xB? Looks like it's a floating point.

    – Kevin Fang
    Jan 2 at 6:18













  • @KevinFang Is a list of values from the first column within the range> = 500

    – Fulana
    Jan 2 at 6:21











  • vetor_x.append(float(X)) why into float?

    – DirtyBit
    Jan 2 at 6:26











  • @user5173426 Because they are not integers

    – Fulana
    Jan 2 at 6:30











  • @Fulana I mean, what's it before this block of code, how do you define and initialize it.

    – Kevin Fang
    Jan 2 at 6:46














2












2








2








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?



#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_xB)
print('####### vetor_xG #######')
print(vetor_xG)
print('####### vetor_yG #######')
print(vetor_yG)
print('####### vetor_xR #######')
print(vetor_xR)
print('####### vetor_yR #######')
print(vetor_yR)


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!










share|improve this question
















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?



#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_xB)
print('####### vetor_xG #######')
print(vetor_xG)
print('####### vetor_yG #######')
print(vetor_yG)
print('####### vetor_xR #######')
print(vetor_xR)
print('####### vetor_yR #######')
print(vetor_yR)


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!







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 21:19







Fulana

















asked Jan 2 at 6:14









FulanaFulana

324




324













  • what is your vector_xB? Looks like it's a floating point.

    – Kevin Fang
    Jan 2 at 6:18













  • @KevinFang Is a list of values from the first column within the range> = 500

    – Fulana
    Jan 2 at 6:21











  • vetor_x.append(float(X)) why into float?

    – DirtyBit
    Jan 2 at 6:26











  • @user5173426 Because they are not integers

    – Fulana
    Jan 2 at 6:30











  • @Fulana I mean, what's it before this block of code, how do you define and initialize it.

    – Kevin Fang
    Jan 2 at 6:46



















  • what is your vector_xB? Looks like it's a floating point.

    – Kevin Fang
    Jan 2 at 6:18













  • @KevinFang Is a list of values from the first column within the range> = 500

    – Fulana
    Jan 2 at 6:21











  • vetor_x.append(float(X)) why into float?

    – DirtyBit
    Jan 2 at 6:26











  • @user5173426 Because they are not integers

    – Fulana
    Jan 2 at 6:30











  • @Fulana I mean, what's it before this block of code, how do you define and initialize it.

    – Kevin Fang
    Jan 2 at 6:46

















what is your vector_xB? Looks like it's a floating point.

– Kevin Fang
Jan 2 at 6:18







what is your vector_xB? Looks like it's a floating point.

– Kevin Fang
Jan 2 at 6:18















@KevinFang Is a list of values from the first column within the range> = 500

– Fulana
Jan 2 at 6:21





@KevinFang Is a list of values from the first column within the range> = 500

– Fulana
Jan 2 at 6:21













vetor_x.append(float(X)) why into float?

– DirtyBit
Jan 2 at 6:26





vetor_x.append(float(X)) why into float?

– DirtyBit
Jan 2 at 6:26













@user5173426 Because they are not integers

– Fulana
Jan 2 at 6:30





@user5173426 Because they are not integers

– Fulana
Jan 2 at 6:30













@Fulana I mean, what's it before this block of code, how do you define and initialize it.

– Kevin Fang
Jan 2 at 6:46





@Fulana I mean, what's it before this block of code, how do you define and initialize it.

– Kevin Fang
Jan 2 at 6:46












1 Answer
1






active

oldest

votes


















0














You cannot split an int or float type into a list.

You can convert them to str using str(vetor_x[i]) first if this is what you're going for.
list() will attempt to split a string into each character.

For example, list('abc') will give you ['a','b','c'].

For int and float, this cannot be done because they are not iterables.



It does not look like you intend to split your vetor_x[i] into each character. It looks like you just want to store the values into vetor_xB[B], in which case, you should be creating an empty list with that many None or 0 variables and then your code to replace them with your



for i in range(0,len(vetor_x)):

if vetor_x[i] <= 500:
vetor_xB[B] = vetor_x[i]
vetor_yB[B] = vetor_y[i]
B += 1
.......


will work.

So you should actually create vetor_xB = [None]*500 to get vetor_xB = [None, None, x500...] before the above code will work






share|improve this answer


























  • Hi @ycx, I want to split that array up there in pairs, by the x-coordinate (first column). Ex: 400 <= B> = 500, 500 <= B> = 600 and 600 <= B> = 700 and store them in new arrays. I do not know if I did not understand what you explained, but it still made a mistake.

    – Fulana
    Jan 2 at 6:55













  • @Fulana If that is the case, you can do a vetor_x.sort() (optional if you want to sort or just store them as of the original order), Then do a direct for i in vetor_x: loop, check for the <= and append the floats to vetor_xB directly.

    – ycx
    Jan 2 at 7:03













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002012%2fpythontypeerror-float-object-is-not-iterable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You cannot split an int or float type into a list.

You can convert them to str using str(vetor_x[i]) first if this is what you're going for.
list() will attempt to split a string into each character.

For example, list('abc') will give you ['a','b','c'].

For int and float, this cannot be done because they are not iterables.



It does not look like you intend to split your vetor_x[i] into each character. It looks like you just want to store the values into vetor_xB[B], in which case, you should be creating an empty list with that many None or 0 variables and then your code to replace them with your



for i in range(0,len(vetor_x)):

if vetor_x[i] <= 500:
vetor_xB[B] = vetor_x[i]
vetor_yB[B] = vetor_y[i]
B += 1
.......


will work.

So you should actually create vetor_xB = [None]*500 to get vetor_xB = [None, None, x500...] before the above code will work






share|improve this answer


























  • Hi @ycx, I want to split that array up there in pairs, by the x-coordinate (first column). Ex: 400 <= B> = 500, 500 <= B> = 600 and 600 <= B> = 700 and store them in new arrays. I do not know if I did not understand what you explained, but it still made a mistake.

    – Fulana
    Jan 2 at 6:55













  • @Fulana If that is the case, you can do a vetor_x.sort() (optional if you want to sort or just store them as of the original order), Then do a direct for i in vetor_x: loop, check for the <= and append the floats to vetor_xB directly.

    – ycx
    Jan 2 at 7:03


















0














You cannot split an int or float type into a list.

You can convert them to str using str(vetor_x[i]) first if this is what you're going for.
list() will attempt to split a string into each character.

For example, list('abc') will give you ['a','b','c'].

For int and float, this cannot be done because they are not iterables.



It does not look like you intend to split your vetor_x[i] into each character. It looks like you just want to store the values into vetor_xB[B], in which case, you should be creating an empty list with that many None or 0 variables and then your code to replace them with your



for i in range(0,len(vetor_x)):

if vetor_x[i] <= 500:
vetor_xB[B] = vetor_x[i]
vetor_yB[B] = vetor_y[i]
B += 1
.......


will work.

So you should actually create vetor_xB = [None]*500 to get vetor_xB = [None, None, x500...] before the above code will work






share|improve this answer


























  • Hi @ycx, I want to split that array up there in pairs, by the x-coordinate (first column). Ex: 400 <= B> = 500, 500 <= B> = 600 and 600 <= B> = 700 and store them in new arrays. I do not know if I did not understand what you explained, but it still made a mistake.

    – Fulana
    Jan 2 at 6:55













  • @Fulana If that is the case, you can do a vetor_x.sort() (optional if you want to sort or just store them as of the original order), Then do a direct for i in vetor_x: loop, check for the <= and append the floats to vetor_xB directly.

    – ycx
    Jan 2 at 7:03
















0












0








0







You cannot split an int or float type into a list.

You can convert them to str using str(vetor_x[i]) first if this is what you're going for.
list() will attempt to split a string into each character.

For example, list('abc') will give you ['a','b','c'].

For int and float, this cannot be done because they are not iterables.



It does not look like you intend to split your vetor_x[i] into each character. It looks like you just want to store the values into vetor_xB[B], in which case, you should be creating an empty list with that many None or 0 variables and then your code to replace them with your



for i in range(0,len(vetor_x)):

if vetor_x[i] <= 500:
vetor_xB[B] = vetor_x[i]
vetor_yB[B] = vetor_y[i]
B += 1
.......


will work.

So you should actually create vetor_xB = [None]*500 to get vetor_xB = [None, None, x500...] before the above code will work






share|improve this answer















You cannot split an int or float type into a list.

You can convert them to str using str(vetor_x[i]) first if this is what you're going for.
list() will attempt to split a string into each character.

For example, list('abc') will give you ['a','b','c'].

For int and float, this cannot be done because they are not iterables.



It does not look like you intend to split your vetor_x[i] into each character. It looks like you just want to store the values into vetor_xB[B], in which case, you should be creating an empty list with that many None or 0 variables and then your code to replace them with your



for i in range(0,len(vetor_x)):

if vetor_x[i] <= 500:
vetor_xB[B] = vetor_x[i]
vetor_yB[B] = vetor_y[i]
B += 1
.......


will work.

So you should actually create vetor_xB = [None]*500 to get vetor_xB = [None, None, x500...] before the above code will work







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 6:35

























answered Jan 2 at 6:29









ycxycx

1,629417




1,629417













  • Hi @ycx, I want to split that array up there in pairs, by the x-coordinate (first column). Ex: 400 <= B> = 500, 500 <= B> = 600 and 600 <= B> = 700 and store them in new arrays. I do not know if I did not understand what you explained, but it still made a mistake.

    – Fulana
    Jan 2 at 6:55













  • @Fulana If that is the case, you can do a vetor_x.sort() (optional if you want to sort or just store them as of the original order), Then do a direct for i in vetor_x: loop, check for the <= and append the floats to vetor_xB directly.

    – ycx
    Jan 2 at 7:03





















  • Hi @ycx, I want to split that array up there in pairs, by the x-coordinate (first column). Ex: 400 <= B> = 500, 500 <= B> = 600 and 600 <= B> = 700 and store them in new arrays. I do not know if I did not understand what you explained, but it still made a mistake.

    – Fulana
    Jan 2 at 6:55













  • @Fulana If that is the case, you can do a vetor_x.sort() (optional if you want to sort or just store them as of the original order), Then do a direct for i in vetor_x: loop, check for the <= and append the floats to vetor_xB directly.

    – ycx
    Jan 2 at 7:03



















Hi @ycx, I want to split that array up there in pairs, by the x-coordinate (first column). Ex: 400 <= B> = 500, 500 <= B> = 600 and 600 <= B> = 700 and store them in new arrays. I do not know if I did not understand what you explained, but it still made a mistake.

– Fulana
Jan 2 at 6:55







Hi @ycx, I want to split that array up there in pairs, by the x-coordinate (first column). Ex: 400 <= B> = 500, 500 <= B> = 600 and 600 <= B> = 700 and store them in new arrays. I do not know if I did not understand what you explained, but it still made a mistake.

– Fulana
Jan 2 at 6:55















@Fulana If that is the case, you can do a vetor_x.sort() (optional if you want to sort or just store them as of the original order), Then do a direct for i in vetor_x: loop, check for the <= and append the floats to vetor_xB directly.

– ycx
Jan 2 at 7:03







@Fulana If that is the case, you can do a vetor_x.sort() (optional if you want to sort or just store them as of the original order), Then do a direct for i in vetor_x: loop, check for the <= and append the floats to vetor_xB directly.

– ycx
Jan 2 at 7:03






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002012%2fpythontypeerror-float-object-is-not-iterable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas