https://github.com/mljs/nearest-vector
Find the nearest point to a sample point
https://github.com/mljs/nearest-vector
Last synced: 9 days ago
JSON representation
Find the nearest point to a sample point
- Host: GitHub
- URL: https://github.com/mljs/nearest-vector
- Owner: mljs
- License: mit
- Created: 2016-10-06T08:30:57.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2025-11-13T15:03:11.000Z (8 months ago)
- Last Synced: 2025-11-13T16:29:24.368Z (8 months ago)
- Language: TypeScript
- Size: 1.21 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
# ml-nearest-vector
[](https://www.npmjs.com/package/ml-nearest-vector)
[](https://www.npmjs.com/package/ml-nearest-vector)
[](https://codecov.io/gh/mljs/spectra-processing)
[](https://github.com/mljs/spectra-processing/blob/main/LICENSE)
> Find the nearest point to a sample point
## Installation
```
$ npm install ml-nearest-vector
```
## [API Documentation](https://mljs.github.io/nearest-vector/)
## Example
```js
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](./LICENSE)