Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

numpy round to nearest 5

#To round to nearest 5
import numpy as np
import pandas as pd
df
>>>
0  34.36
1  1571.80
2  12.54

np.around(df.A.values/5, decimals=0)*5
>>> array([35., 1570., 15.])
#OR 
ar = np.array([34.36, 1571.80, 12.54])
np.around(ar/5, decimals=0)*5
>>> array([35., 1570., 15.])
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #numpy #nearest
ADD COMMENT
Topic
Name
9+1 =