Write a NumPy program to sort the specified number of elements from beginning of a given array.
import numpy as np nums = np.random.rand(10) print("Original array:") print(nums) print("\nSorted first 5 elements:") print(nums[np.argpartition(nums,range(5))])
Sample Output:
Original array: [0.39536213 0.11779404 0.32612381 0.16327394 0.98837963 0.25510787 0.01398678 0.15188239 0.12057667 0.67278699] Sorted first 5 elements: [0.01398678 0.11779404 0.12057667 0.15188239 0.16327394 0.25510787 0.39536213 0.98837963 0.32612381 0.67278699]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer