Is there like a (modified) round function where the output would be either -1,0,1 depending on to what number is the input the closest? E.g. 0 => 0, -2154 => -1, 10 => 1
Currently I am using normal if else statements:
if (i==0):
return 0
elif i > 0:
return 1
else:
return -1
But is there any way how I can make this a one-line code? By for instance using some modified round function.
Aucun commentaire:
Enregistrer un commentaire