Answers for "round array list in python"

4

round python with list

a_list = [1.234, 2.345, 3.45, 1.45]
round_to_whole = [round(num) for num in a_list]

print(round_to_whole)
Posted by: Guest on September-11-2020
0

how to round an array in python

import numpy as np
x = np.round([1.45, 1.50, 1.55])
print(x)
x = np.round([0.28, .50, .64], decimals=1)
print(x)
x = np.round([.5, 1.5, 2.5, 3.5, 4.5]) # rounds to nearest even value
print(x)

#output
#[ 1.  2.  2.]                                                          
#[ 0.3  0.5  0.6]                                                       
#[ 0.  2.  2.  4.  4.]
Posted by: Guest on April-10-2021

Python Answers by Framework

Browse Popular Code Answers by Language