Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ndarray-select

Package Overview
Dependencies
Maintainers
6
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ndarray-select

Linear time selection algorithm for ndarrays

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
212
decreased by-51.6%
Maintainers
6
Weekly downloads
 
Created
Source

ndarray-select

Finds the kth element in an ndarray in linear time with high probability. This implementation is based on the quick select algorithm and mutates the array in place.

build status

Examples

Single list

var pack = require("ndarray-pack")
var ndselect = require("ndarray-select")

var points = pack([0, 0, 1, 2.5, -1])

//Find the median element in the list
var median = ndselect(points, points.shape[0]>>1)

console.log(median.get())
Output
0 2.5 -1

Multiple lists

It is also possible to select vectors (using lexicographical comparisons):

var pack = require("ndarray-pack")
var ndselect = require("ndarray-select")

var points = pack([
  [0, 0, 1],
  [100, 0, 10],
  [50, 1, 10],
  [0, 2.5, -1],
  [-1, -1, -1]
])

//Find the median element in the list
var median = ndselect(points, points.shape[0]>>1)

console.log(median.get(0), median.get(1), median.get(2))
Output
0 2.5 -1

Install

Install using npm:

npm install ndarray-select

API

var ndselect = require("ndarray-select")
ndselect(array, k[, compare])

Selects the kth item from the ndarray array along the first axis of array.

  • array is an ndarray
  • k is the rank of the item which is being selected
  • compare is an optional comparison function that gets a pair of ndarrays as input.

Returns An ndarray view of array.pick(k)

Note This method modifies array. After completion, the element at position k will be in sorted order, with all elements <array.pick(k) occuring before k and all elements >array.pick(k) after k in the list.

ndselect.compile(order, useCompare, dtype)

Precompiles an optimized selection algorithm for an array with the given index order and datatype.

  • order is the order of the ndarray
  • useCompare is a flag which if set uses a comparison function
  • dtype is the datatype of the array

Returns An optimized ndselect function

License

(c) 2014 Mikola Lysenko. MIT License

Keywords

FAQs

Package last updated on 14 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc