Write a NumPy program to get the floor, ceiling and truncated values of the elements of a numpy array
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
import numpy as np
x = np.array([-1.6, -1.5, -0.3, 0.1, 1.4, 1.8, 2.0])
print("Original array:")
print(x)
print("Floor values of the above array elements:")
print(np.floor(x))
print("Ceil values of the above array elements:")
print(np.ceil(x))
print("Truncated values of the above array elements:")
print(np.trunc(x))
Sample Output:
Original array: [-1.6 -1.5 -0.3 0.1 1.4 1.8 2. ] Floor values of the above array elements: [-2. -2. -1. 0. 1. 1. 2.] Ceil values of the above array elements: [-1. -1. -0. 1. 2. 2. 2.] Truncated values of the above array elements: [-1. -1. -0. 0. 1. 1. 2.]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال