python NGT
Project description
python NGT
Install
Python binding with pybind11 (ngtpy) is installed as follows.
pip3 install ngt
If you would like to use python binding with ctypes (ngt), additionally you have to install the NGT library according to the README.
You can install the python bindings with pybind11 and ctypes from source code. You MUST install the NGT library according to the README before installing the python bindings as follows.
pip3 install pybind11
pip3 install numpy
cd NGT_ROOT/python
python3 setup.py sdist
pip3 install dist/ngt-x.x.x.tar.gz
Please note that the search speed of the ngtpy packages from PyPI is slower than that of the ngtpy that is built on your computer so that the package can be run on older CPUs.
Documents
Simple samples
ngtpy (pybind11)
ngtpy(pybind11) can reduce the processing times than ngt(ctypes). It is more effective especially for the short search time.
import ngtpy
import random
dim = 10
objects = []
for i in range(0, 100) :
vector = random.sample(range(100), dim)
objects.append(vector)
query = objects[0]
ngtpy.create(b"tmp", dim)
index = ngtpy.Index(b"tmp")
index.batch_insert(objects)
index.save()
result = index.search(query, 3)
for i, o in enumerate(result) :
print(str(i) + ": " + str(o[0]) + ", " + str(o[1]))
object = index.get_object(o[0])
print(object)
See also sample.py.
ngt (ctypes)
from ngt import base as ngt
import random
dim = 10
objects = []
for i in range(0, 100) :
vector = random.sample(range(100), dim)
objects.append(vector)
query = objects[0]
index = ngt.Index.create(b"tmp", dim)
index.insert(objects)
# You can also insert objects from a file like this.
# index.insert_from_tsv('list.tsv')
index.save()
# You can load saved the index like this.
# index = ngt.Index(b"tmp")
result = index.search(query, 3)
for i, o in enumerate(result) :
print(str(i) + ": " + str(o.id) + ", " + str(o.distance))
object = index.get_object(o.id)
print(object)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for ngt-1.12.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74e3b87f56181e7115be4c5d62ea669313398be9cd3d095c0312ac0b793af781 |
|
MD5 | dd1efb6278b95003addd374215b6ba4c |
|
BLAKE2b-256 | 4bb4e6baed61a85b9aeb751736b7654efdef1cdb051cae5d583e6fb647b5a45c |
Hashes for ngt-1.12.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1370ae2284e7296d0c7e0aa89b5547cda0b05eddd29bf7b8f440af2b0530b6d8 |
|
MD5 | cf0b02faf01ebb0e4dd25e7a260f3452 |
|
BLAKE2b-256 | 0e410dcc700cf7af9a2fa90c55be2e70c9ab7770a336d4740c99b66957654bfc |
Hashes for ngt-1.12.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27fe6d8b7710f09cf6820548d4217d786b120a15daf9d000c7483687ec643ecf |
|
MD5 | b8b6803841531b202e6a6758e434e862 |
|
BLAKE2b-256 | 7b0ed572a4d5b2813825da4e0fa654d3ba5df47fa57f4071be3c44725ca2ab88 |
Hashes for ngt-1.12.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7a98a09a48b95a9985cd64a7e5dfb48c080cdd5fc6d27f7de96b983b14a5287 |
|
MD5 | 3a23c50e329c2b818da12a9b5929994d |
|
BLAKE2b-256 | ef62e310865b78345577438ee33ef634b76b9c225cf055b1a22b9ff8a6095732 |
Hashes for ngt-1.12.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04ba169c709a087ffa263470f5b33ed112e350d103e4d2b536e583efaed2e7b0 |
|
MD5 | f9ded7478d9f3bbf8b100da78cf6babc |
|
BLAKE2b-256 | 8065c3f6a1176d524cf1ce870d31767cc49140ada29d42ef87554f1e0d388f28 |
Hashes for ngt-1.12.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7cfb0924a9799b4714a18cf3a4993a0a514a0bda8746b1195208357823897cc |
|
MD5 | cdfddd00f4646f1519bb723c53e5d96b |
|
BLAKE2b-256 | b8164d62de117a5bc8cf5c18d85087c934ea5f7c65bc77af227d0272ad5ad6c6 |
Hashes for ngt-1.12.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d6928408a729e36f859a19b9e3a84d7c885ed537c2f7ff1a872677471bb3625 |
|
MD5 | 3ee250d2e0754f3f9791e3c2c398b997 |
|
BLAKE2b-256 | 1819d39cc939f0aa284557da5fe42663d7c6e6b2f56df9082c43e90dbe037086 |
Hashes for ngt-1.12.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f06524040ce69c542fc2980a89297756893d054435a933278bab711c300800c3 |
|
MD5 | 7ab7741d7f893a8fa2ded7ff06c6b9f0 |
|
BLAKE2b-256 | 159b57221e25f6f4c7433d8441da94d847e217b3173e83f6bee0613caf5e7f42 |