Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'numpy.float32' object is not iterable

Tags:

python

numpy

I have an array of probabilities:

proba =  :[[0.254 0.556 0.025] [0.898 0567 .112]]

want max value from each as [[0.556] [0.898]]

How i can do it? Tried 2 methods:

 1. max(sublist) for sublist in proba 
 2. proba = map(max,proba)

and getting error "TypeError: 'numpy.float32' object is not iterable"

Any suggestion?

like image 402
Nandan Lahurikar Avatar asked Dec 04 '25 19:12

Nandan Lahurikar


1 Answers

I can notice some problems in your code, first of all, your data list is not in the correct format, commas are missing and there is an extra ':' at the right of the equal sign

proba = [[0.254, 0.556, 0.025], [0.898, 0.567, .112]] 

And then you can get the answer like this :

max_ = [max(i) for i in proba]
like image 163
Fou Avatar answered Dec 07 '25 13:12

Fou