Issue
I just wanted the negative values in my sublist by filtering out all the positive values.
But I am facing the TypeError: 'float' object is not iterable
or sometimes
TypeError: 'numpy.float64' object is not iterable
. ( when there's array to integrate over ),
How to solve this issue ?
My attempt :-
A = [ [-0.234, -0.435, -0.333, 0.999, 0.432, 0.995], [-0.411, -0.205, -0.505, 0.605, 0.705, 0.505], [-0.468, -0.555, -0.343, 0.977, 0.477, 0.777], [-0.244, -0.478, -0.384, 0.931, 0.405, 0.782] ]
Negative_values = []
for i in A:
for m in i:
List_of_Negative_values = list(filter(lambda x: x <= 0, m))
Negative_values.append(List_of_Negative_values)
print('Negative_values',Negative_values)
desired result
A = [ [-0.234, -0.435, -0.333], [-0.411, -0.205, -0.505], [-0.468, -0.555, -0.343], [-0.244, -0.478, -0.384] ]
Solution
try this:
[[i for i in value if i<0]for value in A]
Answered By - to_data
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.