Skip to main content

Sequence / string search with NumPy

Project description

Sequence / string search with NumPy

pip install npsearchsequence

Tested against Windows 10 / Python 3.11 / Anaconda

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])
	"""
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)

    """

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

npsearchsequence-0.10.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

npsearchsequence-0.10-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file npsearchsequence-0.10.tar.gz.

File metadata

  • Download URL: npsearchsequence-0.10.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for npsearchsequence-0.10.tar.gz
Algorithm Hash digest
SHA256 3def027a9795d5114baa1873db964afa4df5d6c502bd037ac0f0981a32054230
MD5 3dc8c961a13ff5a93382137235c51baf
BLAKE2b-256 0a335ec8d37ac993f046263747db6936c8368cfcdc23666da4d19d8dbb058634

See more details on using hashes here.

File details

Details for the file npsearchsequence-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for npsearchsequence-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 1587f1029a2222be0bbda75e4773d1785eb07570af12a310128a1b37e856caa0
MD5 ba7e4df0c6e7787e23eb23e2694cad5b
BLAKE2b-256 0bddd8a32edcfc7acbc3b7c81566d27371d09637860851bd2afa620e0d85c958

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page