Member-only story

Interview question: How can you get the n largest values from a numpy array?

Crystal X
2 min readMar 16, 2023

--

Numpy is an open source library for the Python programming language that adds support for large, multidimensional arrays and matrices, along with a collection of high level mathematical functions to operate on these arrays.

The core functionality of numpy is its ndarray, or n-dimensional array, data structure. These arrays are strided views on memory and differ from Python’s list because all elements of a single array must all be of one type.

The code below shows:-

  1. How to create a numpy array,
  2. How to sort the index of a numpy array,
  3. How to sort a numpy array based on the index of that array,
  4. How to define the number of elements to be looked at in the array,
  5. How to define the negative indexing concept, and
  6. How to sort the n largest values in the array.

There is so much to learn about numpy and this blog post just identifies one area that might come up during an interview.

I personally have taken quite a few numpy courses and watched videos on the subject, endeavouring to pick up as much about this powerful library as I can.

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet