6. Write a Python Numpy program to round up and down all the numbers in the initial array.
The output is:
Initial array = [0.1, 2.4, -7.8, 3.7, 4.3, 5.6]
Expected Answer:
Initial array: [ 0.1 2.4 -7.8 3.7 4.3 5.6]
Round down the numbers: [ 0. 2. -8. 3. 4. 5.]
Round up the numbers: [ 1. 3. -7. 4. 5. 6.]
Sample Answer:
import numpy as np a = np.array([0.1, 2.4, -7.8, 3.7, 4.3, 5.6]) print("Initial array:", a) round_down = np.floor(a) print("\nRound down the numbers:", round_down) round_up = np.ceil(a) print("\nRound up the numbers:", round_up)
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)