How can I transfer
A = [0.12075357905088335, -0.192198145631724, 0.9455373400335009, -0.6811922263715244, 0.7683786941009969, 0.033112227984689206, -0.3812622359989405]
to
A = [[0.12075357905088335], [-0.192198145631724], [0.9455373400335009], [-0.6811922263715244], [0.7683786941009969], [0.033112227984689206], [-0.3812622359989405]]
I tried to the code below but an error occurred:
new = []
for i in A:
new.append.list(i)
TypeError: 'float' object is not iterable
Could anyone help me?
How to Fix Int Object is Not Iterable. One way to fix it is to pass the variable into the range() function. In Python, the range function checks the variable passed into it and returns a series of numbers starting from 0 and stopping right before the specified number.
Explanation: In the above example, we are trying to iterate through a 'for loop' using a float value. But the float is not iterable. Float objects are not iterable because of the absence of the __iter__ method.
Import numpy module using the import numpy as np statement. Pass float numbers to its start, stop, and step argument. For example, np. arange(0.5, 6.5, 1.5) will return the sequence of floating-point numbers starting from 0.5 up to 6.5.
They occur when you try to apply a function on a value of the wrong type. An “'int' object is not iterable” error is raised when you try to iterate over an integer value. To solve this error, make sure that you are iterating over an iterable rather than a number.
Try list comprehension, it is much more convenient:
new = [[i] for i in A]
You are getting TypeError
because you cannot apply list()
function to value of type float
. This function takes an iterable as a parameter and float
is not an iterable.
Another mistake is that you are using new.append._something
instead of new.append(_something)
: append
is a method of a list
object, so you should provide an item to add as a parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With