Write a NumPy program to partition a given array in a specified position and move all the smaller elements values to the left of the partition, and the remaining values to the right, in arbitrary order (based on random choice)
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
import numpy as np
nums = np.array([70, 50, 20, 30, -11, 60, 50, 40])
print("Original array:")
print(nums)
print("\nAfter partitioning on 4 the position:")
print(np.partition(nums, 4))
Sample Output:
Original array: [ 70 50 20 30 -11 60 50 40] After partitioning on 4 the position: [-11 30 20 40 50 50 60 70]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال