npsearchsequence


Namenpsearchsequence JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/npsearchsequence
SummarySequence / string search with NumPy
upload_time2023-11-18 03:23:56
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords sequence search string numpy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Sequence / string search with NumPy

## pip install npsearchsequence

### Tested against Windows 10 / Python 3.11 / Anaconda 


```python
np_search_sequence(a, seq, distance=1):
    """
    Search for the occurrence of a given sequence within a NumPy array.

    Parameters:
    - a (numpy.ndarray): The input NumPy array to search within.
    - seq (numpy.ndarray): The sequence to search for within the array.
    - distance (int, optional): The distance between consecutive elements
      of the sequence in the array. Default is 1.

    Returns:
    numpy.ndarray:
        An array of indices where the given sequence is found in the input array.

    Example:
    seq = np.array([3, 6, 8, 4])
    arr = np.random.randint(0, 9, (1000000,))
    np_search_sequence(a=arr, seq=seq, distance=1)
    array([  8370,  24712,  25143, ..., 999287, 999493, 999805])
	"""
```



```python
np_search_string(string, substring, distance=1):
    r"""
    Search for the occurrence of a given substring within a string using NumPy.

    Parameters:
    - string (str or bytes): The input string to search within.
    - substring (str or bytes): The substring to search for within the string.
    - distance (int, optional): The distance between consecutive characters
      of the substring in the string. Default is 1.

    Returns:
    numpy.ndarray:
        An array of indices where the given substring is found in the input string.

    Example:
    text = '''Welcome! Are you completely new to programming? If not then we presume you will be looking for information about why and how to get started with Python. Fortunately an experienced programmer in any programming language (whatever it may be) can pick up Python very quickly. It's also easy for beginners to use and learn, so jump in!
    Installing Python is generally easy, and nowadays many Linux and UNIX distributions include a recent Python. Even some Windows computers (notably those from HP) now come with Python already installed. If you do need to install Python and aren't confident about the task you can find a few notes on the BeginnersGuide/Download wiki page, but installation is unremarkable on most platforms.'''
    res = np_search_string(string=text*10000, substring='man', distance=1)
    array([  119,   238,   357, ..., 93382, 93533, 93709])
    res2 = np_search_string(string=(text * 10000).encode(), substring=b"man", distance=1)

    """
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/npsearchsequence",
    "name": "npsearchsequence",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "sequence,search,string,numpy",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0a/33/5ec8d37ac993f046263747db6936c8368cfcdc23666da4d19d8dbb058634/npsearchsequence-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Sequence / string search with NumPy\r\n\r\n## pip install npsearchsequence\r\n\r\n### Tested against Windows 10 / Python 3.11 / Anaconda \r\n\r\n\r\n```python\r\nnp_search_sequence(a, seq, distance=1):\r\n    \"\"\"\r\n    Search for the occurrence of a given sequence within a NumPy array.\r\n\r\n    Parameters:\r\n    - a (numpy.ndarray): The input NumPy array to search within.\r\n    - seq (numpy.ndarray): The sequence to search for within the array.\r\n    - distance (int, optional): The distance between consecutive elements\r\n      of the sequence in the array. Default is 1.\r\n\r\n    Returns:\r\n    numpy.ndarray:\r\n        An array of indices where the given sequence is found in the input array.\r\n\r\n    Example:\r\n    seq = np.array([3, 6, 8, 4])\r\n    arr = np.random.randint(0, 9, (1000000,))\r\n    np_search_sequence(a=arr, seq=seq, distance=1)\r\n    array([  8370,  24712,  25143, ..., 999287, 999493, 999805])\r\n\t\"\"\"\r\n```\r\n\r\n\r\n\r\n```python\r\nnp_search_string(string, substring, distance=1):\r\n    r\"\"\"\r\n    Search for the occurrence of a given substring within a string using NumPy.\r\n\r\n    Parameters:\r\n    - string (str or bytes): The input string to search within.\r\n    - substring (str or bytes): The substring to search for within the string.\r\n    - distance (int, optional): The distance between consecutive characters\r\n      of the substring in the string. Default is 1.\r\n\r\n    Returns:\r\n    numpy.ndarray:\r\n        An array of indices where the given substring is found in the input string.\r\n\r\n    Example:\r\n    text = '''Welcome! Are you completely new to programming? If not then we presume you will be looking for information about why and how to get started with Python. Fortunately an experienced programmer in any programming language (whatever it may be) can pick up Python very quickly. It's also easy for beginners to use and learn, so jump in!\r\n    Installing Python is generally easy, and nowadays many Linux and UNIX distributions include a recent Python. Even some Windows computers (notably those from HP) now come with Python already installed. If you do need to install Python and aren't confident about the task you can find a few notes on the BeginnersGuide/Download wiki page, but installation is unremarkable on most platforms.'''\r\n    res = np_search_string(string=text*10000, substring='man', distance=1)\r\n    array([  119,   238,   357, ..., 93382, 93533, 93709])\r\n    res2 = np_search_string(string=(text * 10000).encode(), substring=b\"man\", distance=1)\r\n\r\n    \"\"\"\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Sequence / string search with NumPy",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/npsearchsequence"
    },
    "split_keywords": [
        "sequence",
        "search",
        "string",
        "numpy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0bddd8a32edcfc7acbc3b7c81566d27371d09637860851bd2afa620e0d85c958",
                "md5": "ba7e4df0c6e7787e23eb23e2694cad5b",
                "sha256": "1587f1029a2222be0bbda75e4773d1785eb07570af12a310128a1b37e856caa0"
            },
            "downloads": -1,
            "filename": "npsearchsequence-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ba7e4df0c6e7787e23eb23e2694cad5b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 22050,
            "upload_time": "2023-11-18T03:23:55",
            "upload_time_iso_8601": "2023-11-18T03:23:55.069754Z",
            "url": "https://files.pythonhosted.org/packages/0b/dd/d8a32edcfc7acbc3b7c81566d27371d09637860851bd2afa620e0d85c958/npsearchsequence-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0a335ec8d37ac993f046263747db6936c8368cfcdc23666da4d19d8dbb058634",
                "md5": "3dc8c961a13ff5a93382137235c51baf",
                "sha256": "3def027a9795d5114baa1873db964afa4df5d6c502bd037ac0f0981a32054230"
            },
            "downloads": -1,
            "filename": "npsearchsequence-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "3dc8c961a13ff5a93382137235c51baf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 20875,
            "upload_time": "2023-11-18T03:23:56",
            "upload_time_iso_8601": "2023-11-18T03:23:56.452714Z",
            "url": "https://files.pythonhosted.org/packages/0a/33/5ec8d37ac993f046263747db6936c8368cfcdc23666da4d19d8dbb058634/npsearchsequence-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-18 03:23:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "npsearchsequence",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "npsearchsequence"
}
        
Elapsed time: 0.86400s