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)
"""
Metadata
Release files for npsearchsequence 0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| npsearchsequence-0.10.tar.gz | 20.9 kB | Without provenance | Details for npsearchsequence-0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| npsearchsequence-0.10-py3-none-any.whl | Python 3 | none | any | Details for npsearchsequence-0.10-py3-none-any.whl |
Total release size: 42.9 kB
Release files / npsearchsequence-0.10.tar.gz
| Download URL | npsearchsequence-0.10.tar.gz |
|---|---|
| Size | 20.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3def027a9795d5114baa1873db964afa4df5d6c502bd037ac0f0981a32054230
|
|
BLAKE2b-256 checksum How to use checksums |
0a335ec8d37ac993f046263747db6936c8368cfcdc23666da4d19d8dbb058634
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / npsearchsequence-0.10-py3-none-any.whl
| Download URL | npsearchsequence-0.10-py3-none-any.whl |
|---|---|
| Size | 22.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1587f1029a2222be0bbda75e4773d1785eb07570af12a310128a1b37e856caa0
|
|
BLAKE2b-256 checksum How to use checksums |
0bddd8a32edcfc7acbc3b7c81566d27371d09637860851bd2afa620e0d85c958
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for npsearchsequence 0.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.