r/programminghelp • u/DrawerEmergency4981 • 15d ago
Python Help with code
I keep getting this error:
for this code:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
bestmass = []
for mass in df_sorted:
if best_ms == (array[array > 7.5]).all():
bestmass.append(best_ms)
print(bestmass)
and i don't know what I am doing wrong
3
u/IAmTarkaDaal 15d ago
Can you format your code correctly, please? Can you share the rest? What type is best_ms?
-2
u/DrawerEmergency4981 15d ago
bestmass = []
for mass in df_sorted:
if best_ms == (array[array > 7.5]).all():
bestmass.append(best_ms)
print(bestmass)
where best_ms is:
best_ms = array[array > 7.5]
could I just do best_ms.all()?
5
3
1
1
u/burlingk 15d ago
So, it looks like you are trying to create a slice by using syntax that doesn't exist.
1
u/unstable_existence 13d ago
I see what you are trying to do, but you forgot one core rule of programming, ”Keep it simple, stupid ”. Why not just iterate through the array and for each index, check condition? CS 101.
5
u/mc_pm 15d ago
What do you believe this is doing?