ml-nearest-vector

Find the nearest point to a sample point

Usage no npm install needed!

<script type="module">
  import mlNearestVector from 'https://cdn.skypack.dev/ml-nearest-vector';
</script>

README

nearest-vector

NPM version build status Test coverage David deps npm download

Find the nearest point to a sample point

Installation

$ npm install ml-nearest-vector

API Documentation

Example

import nearestVector, {findNearestVector} from 'ml-nearest-vector');

const nearestVector = require('ml-nearest-vector');

let centers = [[1, 2, 1], [-1, -1, -1]];
// returns the index of the nearest vector
nearestVector(centers, [1, 2, 1]) === 0;

// returns the nearest vector itself
findNearstVector(centers, [1, 2, 1]); // [1, 2, 1]

License

MIT