NDPatch is the package for extracting arbitrary regions from an N-dimensional numpy array assuming it mirrored infinitely.
Installation
The easiest way to install the latest version is by using pip:
$ pip install ndpatch
You may also use Git to clone the repository and install it manually:
$ git clone https://github.com/ashkarin/ndpatch.git $ cd ndpatch $ python setup.py install
Usage
To take a patch from the array:
import numpy as np
import ndpatch
array = np.arange(25).reshape((5,5))
index = (1, 2)
shape = (3, 3)
patch = ndpatch.get_ndpatch(array, shape, index)
# patch =
# [[ 7, 8, 9],
# [12, 13, 14],
# [17, 18, 19]]
To take get a random patch index:
import numpy as np
import ndpatch
array_shape = (5, 5)
index = ndpatch.get_random_patch_index(array_shape)
To extract random patches from the array:
import numpy as np
import ndpatch
npatches = 10
patch_shape = (3, 3)
array = np.arange(100).reshape((10,10))
patches = [ndpatch.get_random_ndpatch(array, patch_shape) for _ in range(npatches)]
To split the 3D array on set of overlapping 3D patches and rebuild it back:
import numpy as np
import ndpatch
array = np.arange(0, 125).reshape((5,5,5))
patch_shape = (4, 3, 3)
overlap = 2
indices = ndpatch.get_patches_indices(array.shape, patch_shape, overlap)
patches = [ndpatch.get_ndpatch(array, patch_shape, index) for index in indices]
reconstructed = ndpatch.reconstruct_from_patches(patches, indices, array.shape, default_value=0)
# Validate
equal = (reconstructed == array)
assert (np.all(equal))
Release files for ndpatch 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ndpatch-0.0.2.tar.gz | 7.9 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ndpatch-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
| ndpatch-0.0.2-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 25.1 kB
Release files / ndpatch-0.0.2.tar.gz
| Download URL | ndpatch-0.0.2.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d137e07a20558ec622436d5352f74eb512d269e62534ad17c7828d9dcfcdba11
|
|
BLAKE2b-256 checksum How to use checksums |
2ad1b80b5f006215548d493058f0578538239b5d5f5723ba6b3741e55b678ce7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / ndpatch-0.0.2-py3-none-any.whl
| Download URL | ndpatch-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01ac201b3f3ee9a640a3fb10fbacbc8d9c24706588d39ab05b8d1fe2332df024
|
|
BLAKE2b-256 checksum How to use checksums |
99c3388c0aae71c4cfc9344e41a787e3c590bbd51a15217bf1d19a9d4b2c7e76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / ndpatch-0.0.2-py2-none-any.whl
| Download URL | ndpatch-0.0.2-py2-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
522438e9a6e26093f90165b7db8b1e64dacec2400ce64d9adf63f70b1b870878
|
|
BLAKE2b-256 checksum How to use checksums |
fc21f1cb459eefe7525493c64224e17cb4644e6f7d9666045bb9314210f2ab8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|