ndfind


Namendfind JSON
Version 0.4.1 PyPI version JSON
download
home_pagehttps://github.com/axil/ndfind
SummaryA collection of cython-optimized search functions for NumPy
upload_time2023-05-08 05:56:20
maintainer
docs_urlNone
authorLev Maximov
requires_python>=3.7
licenseMIT License
keywords find first_above first_nonzero numpy python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ndfind

[![pypi](https://img.shields.io/pypi/v/ndfind.svg)](https://pypi.python.org/pypi/ndfind)
[![python](https://img.shields.io/pypi/pyversions/ndfind.svg)](https://pypi.org/project/ndfind/)
![pytest](https://github.com/axil/ndfind/actions/workflows/python-package.yml/badge.svg)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![License](https://img.shields.io/pypi/l/ndfind)](https://pypi.org/project/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 found
- `first_above(a, v)` finds first element in a that is strictly greater than `v`, 
returns its index or -1 if not found  
- `first_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 in `a` equal to `v`.
    If either a or v (or both) is of floating type, the parameters
    `atol` (absolute tolerance) and `rtol` (relative tolerance) 
    are used for comparison (see `np.isclose()` for details).
   
    Otherwise, returns the `missing` value (-1 by default)
    or raises a `ValueError` if `raises=True`.

    For example,

```python
    >>> 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 in `a` strictly greater than `v`.
    If either a or v (or both) is of floating type, the parameters
    `atol` (absolute tolerance) and `rtol` (relative tolerance) 
    are used for comparison (see `np.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 than `v`, returns the `default` value 
    (-1 by default) or raises a `ValueError` if `raises=True`.

    `sorted`, use binary search to speed things up (works only if the array is sorted)

    
    For example,

```python
    >>> 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 in `a`.

    In 2D and above the the values in `a` are always tested and returned in
    row-major, C-style order.

    For example,

```python
>>> 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/axil/ndfind",
    "name": "ndfind",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "find,first_above,first_nonzero,numpy,python",
    "author": "Lev Maximov",
    "author_email": "lev.maximov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/fb/94/b483cdde885621c1bc8619b7e56d8cc530202be96983da930b11e1260d5e/ndfind-0.4.1.tar.gz",
    "platform": null,
    "description": "\ufeff# ndfind\n\n[![pypi](https://img.shields.io/pypi/v/ndfind.svg)](https://pypi.python.org/pypi/ndfind)\n[![python](https://img.shields.io/pypi/pyversions/ndfind.svg)](https://pypi.org/project/ndfind/)\n![pytest](https://github.com/axil/ndfind/actions/workflows/python-package.yml/badge.svg)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![License](https://img.shields.io/pypi/l/ndfind)](https://pypi.org/project/ndfind/)\n\nA collection of three cython-optimized search functions for NumPy. When the required value is found,\nthey return immediately, without scanning the whole array. It can result in 1000x or larger speedups for \nhuge arrays if the value is located close to the the beginning of the array.\n\n## Installation: \n\n    pip install ndfind\n\n## Contents\n\nBasic usage:  \n- `find(a, v)` finds v in a, returns index of the first match or -1 if not found\n- `first_above(a, v)` finds first element in a that is strictly greater than `v`, \nreturns its index or -1 if not found  \n- `first_nonzero(a)` finds the first nonzero element in a, \nreturns its index or -1 if not found\n\nAdvanced usage:\n- `find(a, v, rtol=1e-05, atol=1e-08, sorted=False, missing=-1, raises=False)`\n    Returns the index of the first element in `a` equal to `v`.\n    If either a or v (or both) is of floating type, the parameters\n    `atol` (absolute tolerance) and `rtol` (relative tolerance) \n    are used for comparison (see `np.isclose()` for details).\n   \n    Otherwise, returns the `missing` value (-1 by default)\n    or raises a `ValueError` if `raises=True`.\n\n    For example,\n\n```python\n    >>> find([3, 1, 4, 1, 5], 4)\n    2\n    >>> find([1, 2, 3], 7)\n    -1\n    >>> find([1.1, 1.2, 1.3], 1.2)\n    1\n    >>> find(np.arange(0, 1, 0.1), 0.3) \n    3\n    >>> find([[3, 8, 4], [5, 2, 7]], 7)\n    (1, 2)\n    >>> find([[3, 8, 4], [5, 2, 7]], 9)\n    -1\n    >>> find([999980., 999990., 1e6], 1e6)\n    1\n    >>> find([999980., 999990., 1e6], 1e6, rtol=1e-9)\n    2\n```\n\n- `first_above(a, v, sorted=False, missing=-1, raises=False)`\n    Returns the index of the first element in `a` strictly greater than `v`.\n    If either a or v (or both) is of floating type, the parameters\n    `atol` (absolute tolerance) and `rtol` (relative tolerance) \n    are used for comparison (see `np.isclose()` for details).\n\n    In 2D and above the the values in `a` are always tested and returned in\n    row-major, C-style order.\n\n    If there is no value in `a` greater than `v`, returns the `default` value \n    (-1 by default) or raises a `ValueError` if `raises=True`.\n\n    `sorted`, use binary search to speed things up (works only if the array is sorted)\n\n    \n    For example,\n\n```python\n    >>> first_above([4, 5, 8, 2, 7], 6)\n    2 \n    >>> first_above([[4, 5, 8], [2, 7, 3]], 6)\n    (0, 2) \n    >>> first_above([5, 6, 7], 9)\n    3 \n```\n\n- `first_nonzero(a, missing=-1, raises=False)`\n    Returns the index of the first nonzero element in `a`.\n\n    In 2D and above the the values in `a` are always tested and returned in\n    row-major, C-style order.\n\n    For example,\n\n```python\n>>> first_nonzero([0, 0, 7, 0, 5])\n2\n>>> first_nonzero([False, True, False, False, True])\n1\n>>> first_nonzero([[0, 0, 0, 0], [0, 0, 5, 3]])\n(1, 2)\n```\n\n## Testing\n\nRun `pytest` in the project root.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A collection of cython-optimized search functions for NumPy",
    "version": "0.4.1",
    "project_urls": {
        "Homepage": "https://github.com/axil/ndfind"
    },
    "split_keywords": [
        "find",
        "first_above",
        "first_nonzero",
        "numpy",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b1535bdefbe637e8f4b72b6e8ccae087bc3efbd44f9e68296d9b284f08ab04a",
                "md5": "b1c64cad0389ae1736c612edbd6395e4",
                "sha256": "737f352dace32c61e49d2eecdfa4c54ed2c0eff8195e52686509e8a88fa66067"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "b1c64cad0389ae1736c612edbd6395e4",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.7",
            "size": 431402,
            "upload_time": "2023-05-08T06:03:22",
            "upload_time_iso_8601": "2023-05-08T06:03:22.450570Z",
            "url": "https://files.pythonhosted.org/packages/8b/15/35bdefbe637e8f4b72b6e8ccae087bc3efbd44f9e68296d9b284f08ab04a/ndfind-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "abe0d8ab4d5d73da5723aa58f6513c454b9b7cbabc68226f19ee0291a29df712",
                "md5": "fc22391ad876ccbfb58df8d864c9006c",
                "sha256": "fc255c699223165b539722ec978155a77c3540400677170525febb2022dc1580"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "fc22391ad876ccbfb58df8d864c9006c",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.7",
            "size": 2514563,
            "upload_time": "2023-05-08T06:00:46",
            "upload_time_iso_8601": "2023-05-08T06:00:46.469552Z",
            "url": "https://files.pythonhosted.org/packages/ab/e0/d8ab4d5d73da5723aa58f6513c454b9b7cbabc68226f19ee0291a29df712/ndfind-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46e5c1d611d392ad4628f5087d41a53abf1d8b41abf439c4b8274d90cc731b5a",
                "md5": "b665f8bddac75c0c5dde31abbab6227a",
                "sha256": "096b5019533471efe2c5309972f999e857a045dd2bf9eced8b0f1c6c4c845726"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp310-cp310-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "b665f8bddac75c0c5dde31abbab6227a",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.7",
            "size": 282996,
            "upload_time": "2023-05-08T06:02:41",
            "upload_time_iso_8601": "2023-05-08T06:02:41.435570Z",
            "url": "https://files.pythonhosted.org/packages/46/e5/c1d611d392ad4628f5087d41a53abf1d8b41abf439c4b8274d90cc731b5a/ndfind-0.4.1-cp310-cp310-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "78a44fd4bdff71dd7ff4689226372fea137ad7dd66ce24c0d634aee2670a638c",
                "md5": "46bd28d535f79f633c0bfed161387476",
                "sha256": "8dbdccfc5b60c9fc41f50ea7bc34ff1c749b545808163f6598baa2c782ad6dff"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "46bd28d535f79f633c0bfed161387476",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.7",
            "size": 429057,
            "upload_time": "2023-05-08T06:03:25",
            "upload_time_iso_8601": "2023-05-08T06:03:25.030746Z",
            "url": "https://files.pythonhosted.org/packages/78/a4/4fd4bdff71dd7ff4689226372fea137ad7dd66ce24c0d634aee2670a638c/ndfind-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d3dfb8153fbd5169b33fd8ca40c92df3675813a8005e111c320d7db3e0dbb17d",
                "md5": "341d34a225c3a2ef9c199ae2e89aa137",
                "sha256": "fc41a5105bc41aa979f47bdd616f06d9f2252c4814c1a168ec8c9ebe6041b72a"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "341d34a225c3a2ef9c199ae2e89aa137",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.7",
            "size": 2731031,
            "upload_time": "2023-05-08T06:00:48",
            "upload_time_iso_8601": "2023-05-08T06:00:48.792618Z",
            "url": "https://files.pythonhosted.org/packages/d3/df/b8153fbd5169b33fd8ca40c92df3675813a8005e111c320d7db3e0dbb17d/ndfind-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bcf6f637befbddc985423ffee01ef4cf075d9ceb661841d1ca47f52cf0315458",
                "md5": "77e2da63d901a23056333c5c3e6e7692",
                "sha256": "29f822c294bcb24a9802aa8616109ccda521b89874343eb890fc61f8b1e8522f"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp311-cp311-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "77e2da63d901a23056333c5c3e6e7692",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.7",
            "size": 284017,
            "upload_time": "2023-05-08T06:02:43",
            "upload_time_iso_8601": "2023-05-08T06:02:43.551312Z",
            "url": "https://files.pythonhosted.org/packages/bc/f6/f637befbddc985423ffee01ef4cf075d9ceb661841d1ca47f52cf0315458/ndfind-0.4.1-cp311-cp311-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a79e7af2ef64be3b5d43ca0ac38ae1584bef9351c94b694e59d87d4ce22b0392",
                "md5": "cfbb899cf36484ddbc761e1a1a8040ec",
                "sha256": "4997a5c811487783256392a47d99408f725e6912a4f791ae6b4c9506f72c2e83"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp38-cp38-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "cfbb899cf36484ddbc761e1a1a8040ec",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.7",
            "size": 420591,
            "upload_time": "2023-05-08T06:03:27",
            "upload_time_iso_8601": "2023-05-08T06:03:27.090048Z",
            "url": "https://files.pythonhosted.org/packages/a7/9e/7af2ef64be3b5d43ca0ac38ae1584bef9351c94b694e59d87d4ce22b0392/ndfind-0.4.1-cp38-cp38-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17f7276b350f94eeae7f081189dda9dd87026bba3c1039bc54666149abcec2c4",
                "md5": "fdce2e60569e640070e3c7d03d815572",
                "sha256": "1db561592983361aca85c88d35fc4f7a75e2d0ad5273ebe9a32cc40e23a2ef6e"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "fdce2e60569e640070e3c7d03d815572",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.7",
            "size": 2655262,
            "upload_time": "2023-05-08T06:00:51",
            "upload_time_iso_8601": "2023-05-08T06:00:51.076376Z",
            "url": "https://files.pythonhosted.org/packages/17/f7/276b350f94eeae7f081189dda9dd87026bba3c1039bc54666149abcec2c4/ndfind-0.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7135f4378432ede8d9569e4f5bf2a24484af3843dc52dff76c0ce3d2a7cdc5ed",
                "md5": "26b7587d20c3d6f6de9ba40fe9923f27",
                "sha256": "b0e621d4c6ad857d548a36970e2d9ddd2cd77a5d8094adb76f56483f0df54f89"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp38-cp38-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "26b7587d20c3d6f6de9ba40fe9923f27",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.7",
            "size": 294638,
            "upload_time": "2023-05-08T06:02:45",
            "upload_time_iso_8601": "2023-05-08T06:02:45.510973Z",
            "url": "https://files.pythonhosted.org/packages/71/35/f4378432ede8d9569e4f5bf2a24484af3843dc52dff76c0ce3d2a7cdc5ed/ndfind-0.4.1-cp38-cp38-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38f67127d6492e18a2b6be41992dfaa18f3f7bc2cd382e8fb6e5d07a418520b0",
                "md5": "748ec5818db47da22b37a2bcecf4fd9e",
                "sha256": "8a0df0f7b2cc110034484194638eeef860f7d450f9e53599bbf12eed190512eb"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "748ec5818db47da22b37a2bcecf4fd9e",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.7",
            "size": 439528,
            "upload_time": "2023-05-08T06:03:28",
            "upload_time_iso_8601": "2023-05-08T06:03:28.846397Z",
            "url": "https://files.pythonhosted.org/packages/38/f6/7127d6492e18a2b6be41992dfaa18f3f7bc2cd382e8fb6e5d07a418520b0/ndfind-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ebfde9846bcbf89a227cf60d4fb358a4db1843b821dc4002a0d32d2b6bffe88c",
                "md5": "6723c6869d77adf869f8117147450ded",
                "sha256": "889e47047c275d972017460a0ce9f4975b4663fb88fb23ac76180e07687f1c0f"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "6723c6869d77adf869f8117147450ded",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.7",
            "size": 2562167,
            "upload_time": "2023-05-08T06:00:53",
            "upload_time_iso_8601": "2023-05-08T06:00:53.536854Z",
            "url": "https://files.pythonhosted.org/packages/eb/fd/e9846bcbf89a227cf60d4fb358a4db1843b821dc4002a0d32d2b6bffe88c/ndfind-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8406e49ba5aaf17a09b75b6db2e07f479de852653c5c60fe2753cbc32948533",
                "md5": "e3ae756a803cc4527ca7925af9590814",
                "sha256": "a415580b43c305c61c9ed35b849a5e1727edc206ab8ea168fb67b75177c60f93"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1-cp39-cp39-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "e3ae756a803cc4527ca7925af9590814",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.7",
            "size": 290663,
            "upload_time": "2023-05-08T06:02:47",
            "upload_time_iso_8601": "2023-05-08T06:02:47.060073Z",
            "url": "https://files.pythonhosted.org/packages/e8/40/6e49ba5aaf17a09b75b6db2e07f479de852653c5c60fe2753cbc32948533/ndfind-0.4.1-cp39-cp39-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fb94b483cdde885621c1bc8619b7e56d8cc530202be96983da930b11e1260d5e",
                "md5": "25e1764c1979c875becd5a7d5219f7d2",
                "sha256": "db3ec9bbfca1a027a31d47ed8c449371e0c2e876da7a51f032e49639e91d3f49"
            },
            "downloads": -1,
            "filename": "ndfind-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "25e1764c1979c875becd5a7d5219f7d2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 300776,
            "upload_time": "2023-05-08T05:56:20",
            "upload_time_iso_8601": "2023-05-08T05:56:20.872128Z",
            "url": "https://files.pythonhosted.org/packages/fb/94/b483cdde885621c1bc8619b7e56d8cc530202be96983da930b11e1260d5e/ndfind-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-08 05:56:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "axil",
    "github_project": "ndfind",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "ndfind"
}
        
Elapsed time: 0.07186s