Write a NumPy program to create an array that represents the rank of each item of a given array.
import numpy as numpy array = numpy.array([24, 27, 30, 29, 18, 14]) print("Original array:") print(array) argsort_array = array.argsort() ranks_array = numpy.empty_like(argsort_array) ranks_array[argsort_array] = numpy.arange(len(array)) print("\nRank of each item of the said array:") print(ranks_array)
Sample Output:
Original array: [24 27 30 29 18 14] Rank of each item of the said array: [2 3 5 4 1 0]
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