A collection of cython-optimized search functions for NumPy
Project description
ndfind
A collection of three cython-optimized search functions for NumPy. When the required value is found, they return immediately, without scanning the whole array. It can result in 1000x or larger speedups for huge arrays if the value is located close to the the beginning of the array.
Installation:
pip install ndfind
Contents
Basic usage:
find(a, v)
finds v in a, returns index of the first match or -1 if not foundfirst_above(a, v)
finds first element in a that is strictly greater thanv
, returns its index or -1 if not foundfirst_nonzero(a)
finds the first nonzero element in a, returns its index or -1 if not found
Advanced usage:
-
find(a, v, rtol=1e-05, atol=1e-08, sorted=False, missing=-1, raises=False)
Returns the index of the first element ina
equal tov
. If either a or v (or both) is of floating type, the parametersatol
(absolute tolerance) andrtol
(relative tolerance) are used for comparison (seenp.isclose()
for details).Otherwise, returns the
missing
value (-1 by default) or raises aValueError
ifraises=True
.For example,
>>> find([3, 1, 4, 1, 5], 4)
2
>>> find([1, 2, 3], 7)
-1
>>> find([1.1, 1.2, 1.3], 1.2)
1
>>> find(np.arange(0, 1, 0.1), 0.3)
3
>>> find([[3, 8, 4], [5, 2, 7]], 7)
(1, 2)
>>> find([[3, 8, 4], [5, 2, 7]], 9)
-1
>>> find([999980., 999990., 1e6], 1e6)
1
>>> find([999980., 999990., 1e6], 1e6, rtol=1e-9)
2
-
first_above(a, v, sorted=False, missing=-1, raises=False)
Returns the index of the first element ina
strictly greater thanv
. If either a or v (or both) is of floating type, the parametersatol
(absolute tolerance) andrtol
(relative tolerance) are used for comparison (seenp.isclose()
for details).In 2D and above the the values in
a
are always tested and returned in row-major, C-style order.If there is no value in
a
greater thanv
, returns thedefault
value (-1 by default) or raises aValueError
ifraises=True
.sorted
, use binary search to speed things up (works only if the array is sorted)For example,
>>> first_above([4, 5, 8, 2, 7], 6)
2
>>> first_above([[4, 5, 8], [2, 7, 3]], 6)
(0, 2)
>>> first_above([5, 6, 7], 9)
3
-
first_nonzero(a, missing=-1, raises=False)
Returns the index of the first nonzero element ina
.In 2D and above the the values in
a
are always tested and returned in row-major, C-style order.For example,
>>> first_nonzero([0, 0, 7, 0, 5])
2
>>> first_nonzero([False, True, False, False, True])
1
>>> first_nonzero([[0, 0, 0, 0], [0, 0, 5, 3]])
(1, 2)
Testing
Run pytest
in the project root.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file ndfind-0.4.1.tar.gz
.
File metadata
- Download URL: ndfind-0.4.1.tar.gz
- Upload date:
- Size: 300.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db3ec9bbfca1a027a31d47ed8c449371e0c2e876da7a51f032e49639e91d3f49 |
|
MD5 | 25e1764c1979c875becd5a7d5219f7d2 |
|
BLAKE2b-256 | fb94b483cdde885621c1bc8619b7e56d8cc530202be96983da930b11e1260d5e |
Provenance
File details
Details for the file ndfind-0.4.1-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 284.0 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29f822c294bcb24a9802aa8616109ccda521b89874343eb890fc61f8b1e8522f |
|
MD5 | 77e2da63d901a23056333c5c3e6e7692 |
|
BLAKE2b-256 | bcf6f637befbddc985423ffee01ef4cf075d9ceb661841d1ca47f52cf0315458 |
Provenance
File details
Details for the file ndfind-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc41a5105bc41aa979f47bdd616f06d9f2252c4814c1a168ec8c9ebe6041b72a |
|
MD5 | 341d34a225c3a2ef9c199ae2e89aa137 |
|
BLAKE2b-256 | d3dfb8153fbd5169b33fd8ca40c92df3675813a8005e111c320d7db3e0dbb17d |
Provenance
File details
Details for the file ndfind-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 429.1 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dbdccfc5b60c9fc41f50ea7bc34ff1c749b545808163f6598baa2c782ad6dff |
|
MD5 | 46bd28d535f79f633c0bfed161387476 |
|
BLAKE2b-256 | 78a44fd4bdff71dd7ff4689226372fea137ad7dd66ce24c0d634aee2670a638c |
Provenance
File details
Details for the file ndfind-0.4.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 283.0 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 096b5019533471efe2c5309972f999e857a045dd2bf9eced8b0f1c6c4c845726 |
|
MD5 | b665f8bddac75c0c5dde31abbab6227a |
|
BLAKE2b-256 | 46e5c1d611d392ad4628f5087d41a53abf1d8b41abf439c4b8274d90cc731b5a |
Provenance
File details
Details for the file ndfind-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc255c699223165b539722ec978155a77c3540400677170525febb2022dc1580 |
|
MD5 | fc22391ad876ccbfb58df8d864c9006c |
|
BLAKE2b-256 | abe0d8ab4d5d73da5723aa58f6513c454b9b7cbabc68226f19ee0291a29df712 |
Provenance
File details
Details for the file ndfind-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 431.4 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 737f352dace32c61e49d2eecdfa4c54ed2c0eff8195e52686509e8a88fa66067 |
|
MD5 | b1c64cad0389ae1736c612edbd6395e4 |
|
BLAKE2b-256 | 8b1535bdefbe637e8f4b72b6e8ccae087bc3efbd44f9e68296d9b284f08ab04a |
Provenance
File details
Details for the file ndfind-0.4.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 290.7 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a415580b43c305c61c9ed35b849a5e1727edc206ab8ea168fb67b75177c60f93 |
|
MD5 | e3ae756a803cc4527ca7925af9590814 |
|
BLAKE2b-256 | e8406e49ba5aaf17a09b75b6db2e07f479de852653c5c60fe2753cbc32948533 |
Provenance
File details
Details for the file ndfind-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 889e47047c275d972017460a0ce9f4975b4663fb88fb23ac76180e07687f1c0f |
|
MD5 | 6723c6869d77adf869f8117147450ded |
|
BLAKE2b-256 | ebfde9846bcbf89a227cf60d4fb358a4db1843b821dc4002a0d32d2b6bffe88c |
Provenance
File details
Details for the file ndfind-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 439.5 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a0df0f7b2cc110034484194638eeef860f7d450f9e53599bbf12eed190512eb |
|
MD5 | 748ec5818db47da22b37a2bcecf4fd9e |
|
BLAKE2b-256 | 38f67127d6492e18a2b6be41992dfaa18f3f7bc2cd382e8fb6e5d07a418520b0 |
Provenance
File details
Details for the file ndfind-0.4.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 294.6 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0e621d4c6ad857d548a36970e2d9ddd2cd77a5d8094adb76f56483f0df54f89 |
|
MD5 | 26b7587d20c3d6f6de9ba40fe9923f27 |
|
BLAKE2b-256 | 7135f4378432ede8d9569e4f5bf2a24484af3843dc52dff76c0ce3d2a7cdc5ed |
Provenance
File details
Details for the file ndfind-0.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1db561592983361aca85c88d35fc4f7a75e2d0ad5273ebe9a32cc40e23a2ef6e |
|
MD5 | fdce2e60569e640070e3c7d03d815572 |
|
BLAKE2b-256 | 17f7276b350f94eeae7f081189dda9dd87026bba3c1039bc54666149abcec2c4 |
Provenance
File details
Details for the file ndfind-0.4.1-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ndfind-0.4.1-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 420.6 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4997a5c811487783256392a47d99408f725e6912a4f791ae6b4c9506f72c2e83 |
|
MD5 | cfbb899cf36484ddbc761e1a1a8040ec |
|
BLAKE2b-256 | a79e7af2ef64be3b5d43ca0ac38ae1584bef9351c94b694e59d87d4ce22b0392 |