Member-only story
Interview question: How can you get the n largest values from a numpy array?
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:-
- How to create a numpy array,
- How to sort the index of a numpy array,
- How to sort a numpy array based on the index of that array,
- How to define the number of elements to be looked at in the array,
- How to define the negative indexing concept, and
- 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.