How to get the n-largest values of an array using NumPy? Last Updated : 15 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Let's see the program for how to get the n-largest values of an array using NumPy library. For getting n-largest values from a NumPy array we have to first sort the NumPy array using numpy.argsort() function of NumPy then applying slicing concept with negative indexing. Syntax: numpy.argsort(arr, axis=-1, kind=’quicksort’, order=None) Return: [index_array, ndarray] Array of indices that sort arr along the specified axis.If arr is one-dimensional then arr[index_array] returns a sorted arr. Let's see an example: Example 1: Getting the 1st largest value from a NumPy array. Python3 # import library import numpy as np # create numpy 1d-array arr = np.array([2, 0, 1, 5, 4, 1, 9]) print("Given array:", arr) # sort an array in # ascending order # np.argsort() return # array of indices for # sorted array sorted_index_array = np.argsort(arr) # sorted array sorted_array = arr[sorted_index_array] print("Sorted array:", sorted_array) # we want 1 largest value n = 1 # we are using negative # indexing concept # take n largest value rslt = sorted_array[-n : ] # show the output print("{} largest value:".format(n), rslt[0]) Output: Given array: [2 0 1 5 4 1 9] Sorted array: [0 1 1 2 4 5 9] 1 largest value: 9 Example 2: Getting the 3-largest values from a NumPy array. Python3 # import library import numpy as np # create numpy 1d-array arr = np.array([2, 0, 1, 5, 4, 1, 9]) print("Given array:", arr) # sort an array in # ascending order # np.argsort() return # array of indices for # sorted array sorted_index_array = np.argsort(arr) # sorted array sorted_array = arr[sorted_index_array] print("Sorted array:", sorted_array) # we want 3 largest value n = 3 # we are using negative # indexing concept # find n largest value rslt = sorted_array[-n : ] # show the output print("{} largest value:".format(n), rslt) Output: Given array: [2 0 1 5 4 1 9] Sorted array: [0 1 1 2 4 5 9] 3 largest value: [4 5 9] Comment More infoAdvertise with us Next Article Company-wise Practice Problems A ankthon Follow Improve Article Tags : Python Python-numpy Python numpy-program Python numpy-Mathematical Function Practice Tags : python Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like