Summary
Provide an intuitive way to make ndarray indexing variable like this:
from npindex import npidx green_idx = npidx[:, :, 1] # assume that im1 and im2 are numpy ndarray # that were return values of OpenCV's cv2.imread() function. green_of_im1 = im1[green_idx] green_of_im2 = im2[green_idx]
This is all npindex does.
Usage
The signagure of npindex.npidx
npidx(d1, d2=None, d3=None, /)
Only positional argument is permitted. And 1, 2, 3 dimentional ndarrays are only supported.
Each arguments are treated as a slice object when arguments are passed in the form of slicing notation:
npidx[1:2, 3:4, 5:6] # => (slice(1, 2, None), slice(3, 4, None), slice(5, 6, None))
Or, treated as an integer when arguments are passed just as an integer:
npidx[1, 2, 3] # => (1, 2, 3)
What is the point of that? OK, I’ll show you it in the next section.
How to use effectively
We can access to items of ndarray by passing one or more slice objects inside its square brackets like this:
import numpy as np from npindex import npidx a = np.arange(10) # a => array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) i = npidx[1:5] # i => slice(1, 5, None) a[i] # => array([1, 2, 3, 4]) a2 = a.reshape(2, 5) # a => array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) i2 = npidx[:, 2:4] # i2 => (slice(None, None, None), slice(2, 4, None)) a2[i2] # => array([[2, 3], [7, 8]])
And it is also possible to access just one value from ndarray:
import numpy as np from npindex import npidx a = np.arange(10) # a => array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) i = npidx[1] # i => 1 a[i] # => 1 a2 = a.reshape(2, 5) # a => array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) i2 = npidx[0, 4] # (0, 4) a2[i2] # => 4
When we want to access values from two or more ndarray object, npidx is useful.:
import numpy as np from npindex import npidx range = npidx[100:300, 150:250, :] small_im1 = im1[range] small_im2 = im2[range]
Install
Linux, Windows, macOS:
pip install npindex
Metadata
Release files for npindex 0.1.1
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 |
|---|---|---|---|---|
| npindex-0.1.1.tar.gz | 2.7 kB | Without provenance | Details for npindex-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| npindex-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for npindex-0.1.1-py3-none-any.whl |
Total release size: 5.3 kB
Release files / npindex-0.1.1.tar.gz
| Download URL | npindex-0.1.1.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c35b410becf0c0c7b860eaa70a859cf203cb229945f2ce4fa106e62827c9fe4e
|
|
BLAKE2b-256 checksum How to use checksums |
a5babe9217868c25965f780fa9e258c71fbeaad04038c3a91c268c538ef0497f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.6 CPython/3.9.4 Darwin/20.5.0
|
Release files / npindex-0.1.1-py3-none-any.whl
| Download URL | npindex-0.1.1-py3-none-any.whl |
|---|---|
| Size | 2.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
924f0dca9bba27188b831a6d30114f4f966fe5dab5a0fdd18611707a4e895513
|
|
BLAKE2b-256 checksum How to use checksums |
22d14d9798176571306e9d6694a054e16e23f76aa97409568b79f8e0225d7107
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.6 CPython/3.9.4 Darwin/20.5.0
|
Security for npindex 0.1.1
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.