Skip to main content

Splits a numpy array or a list based on the given indices or ranges and returns the split arrays.

pip install numpyslicesplit

Tested against Windows 10 / Python 3.11 / Anaconda

How to use it in Python

Parameters:
a (numpy array/list): The input array/list to be split.
splits (list): The indices or ranges to split the array on.
delete (bool, optional): If True, removes the specified indices from the split arrays,
if not it keeps them and deletes the others
Defaults to True.

Returns:
list: A list of numpy arrays split based on the given indices or ranges.

Example:
from numpyslicesplit import np_slice_split
a = np.arange(1000).reshape(100, 10)[..., 0]
splits = [(3, 5), (9, 14), (24, 30), (41, 43)]
s1 = np_slice_split(a, splits, delete=True)
print(f"{s1=}")
s2 = np_slice_split(a, splits, delete=False)
print(f"{s2=}")

splits = [3, 4, 5, 65, 7, 4, 6, 63, 2, 5, (0, 10)]
s1 = np_slice_split(a.tolist(), splits, delete=True)
print(f"{s1=}")
s2 = np_slice_split(a.tolist(), splits, delete=False)
print(f"{s2=}")


# s1=[array([ 0, 10, 20]), array([50, 60, 70, 80]),
#     array([140, 150, 160, 170, 180, 190, 200, 210, 220, 230]),
#     array([300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400]),
#     array([430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540, 550,
#        560, 570, 580, 590, 600, 610, 620, 630, 640, 650, 660, 670, 680,
#        690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, 810,
#        820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940,
#        950, 960, 970, 980, 990])]


# s1=[[100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230,
# 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380
# , 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500,
# 510, 520, 530, 540, 550, 560, 570, 580, 590, 600, 610, 620],
#  [640], [660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760,
#  770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890,
#  900, 910, 920, 930,
# 940, 950, 960, 970, 980, 990]]
# s2=[[0, 10, 20, 30, 40, 50, 60, 70, 80, 90], [630], [650]]

Metadata

Release files for numpyslicesplit 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for numpyslicesplit 0.10
File Size Uploaded Provenance Actions
numpyslicesplit-0.10.tar.gz 21.0 kB Without provenance Details for numpyslicesplit-0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for numpyslicesplit 0.10
File Interpreter ABI Platform Actions
numpyslicesplit-0.10-py3-none-any.whl Python 3 none any Details for numpyslicesplit-0.10-py3-none-any.whl

Total release size: 42.5 kB

Release files / numpyslicesplit-0.10.tar.gz

Download URL numpyslicesplit-0.10.tar.gz
Size 21.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a0d7ba649cf0d796247840c87e216ea37727b43073f35533cbfdf3cca539776f
BLAKE2b-256 checksum
How to use checksums
d316aadd0d8e812ad2d7711c86d3648c034ca82517c4a160c04402f98c165555
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / numpyslicesplit-0.10-py3-none-any.whl

Download URL numpyslicesplit-0.10-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
721c6c2b63d4dfdc7ab981911e03d6c51825832222100e12ea8dc720982f5a8a
BLAKE2b-256 checksum
How to use checksums
fb41c9a3cf6384f609ae5dec855509613edad8c162c3f4eaa10e039c4d1dc77e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Security for numpyslicesplit 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.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page