Parse numpy style advanced indexing notation from string.
Project description
sliceparser
Introduction
As per this question, creating from string slice object, or even advanced indexing tuple, is a common requirement. However, there exists few robust and safe solution, if at all, to solve the problem. Therefore I attempt to solve it and expose programmatic interface via PyPI. I also put my answer to the question above.
This repo is adapted from my Gist.
Install
pip install sliceparser
# or pip3 install sliceparser
Usage
import sliceparser
a = [1,2,3,4]
assert a[sliceparser.parse_slice('2:')] == a[2:]
assert a[sliceparser.parse_slice('::2')] == a[::2]
assert a[sliceparser.parse_slice('1')] == a[1]
import numpy as np
A = np.eye(3)
assert np.array_equal(A[sliceparser.parse_slice('0, 1:')], A[0,1:])
assert np.array_equal(A[sliceparser.parse_slice('..., 2')], A[..., 2])
etc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sliceparser-0.9.1b0.tar.gz
(3.1 kB
view details)
File details
Details for the file sliceparser-0.9.1b0.tar.gz
.
File metadata
- Download URL: sliceparser-0.9.1b0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
172a316b6e03ce3c5e7d1fbf68460ca1300ed097595481dfe26548a178ba0de8
|
|
MD5 |
1cf04c339272e03317669b1acda40b85
|
|
BLAKE2b-256 |
a8ae80507d2962365f02ce17dad0e82206c6addc1c562a03a459fb934aa09bd2
|