Numpy.partition in JavaScript

Is there an equivalent available numpy.partitionin JavaScript through the library or inline?

It seems that not one of the popular libraries like underscore.js provides such a function. I ask because I would like to find the nhighest (or lowest) elements in the array for the general case, without having to implement quickselect or introselect myself.

Dividing the array by index nrebuilds the array so that the at element is nin sorted order, and all elements with an index are nlarger than this element in n. Alternatively, items with indexes nmay be less than item c n. In any case, this is a partial view that guarantees the position of a particular element and the distribution of elements above and below.

Full sorting, of course, satisfies the same conditions, but works in O(n log n)time, while separation is usually done in O(n)time (average case for quick selection, worst case for introselect).

The jQuery QuickSelect plugin does something completely different, despite its promising name.

Part of the motivation for this question: Can I use Math.min to get the second smallest number from an array?

+4
source share
1 answer

Package for quick selection.

Github

NPM

(I never used this package, but from README it seems to be looking for OP)

+1
source

Source: https://habr.com/ru/post/1689398/


All Articles