Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the absolute value for an array in python?

Tags:

python

How to calculate the absolute value for an array in python?

for example: a = [5,-2,-6,5]

I want to know the max of abs(a), and the answer should be 6. Thank you!

like image 263
wesley Avatar asked Nov 30 '22 20:11

wesley


1 Answers

max(abs(i) for i in [5, -2, -6, 5])

like image 151
Anorov Avatar answered Dec 06 '22 10:12

Anorov