Round to two decimals
Write a NumPy program to round elements to two decimal places.
[4.8757, 2.4578]
[4.88 2.46]
Approach
np.round(a, 2).
Solution
import numpy as npprint(np.round(np.array([4.8757, 2.4578]), 2))[4.88 2.46]
Rounding gives 4.88 and 2.46; the original sample (4.86, 2.45) was not rounded correctly.
Learn the concept
New to this topic? Read the lesson, then come back.