Splits a numpy array or a list based on the given indices or ranges and returns the split arrays.
Project description
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]]
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
numpyslicesplit-0.10.tar.gz
(21.0 kB
view details)
Built Distribution
File details
Details for the file numpyslicesplit-0.10.tar.gz
.
File metadata
- Download URL: numpyslicesplit-0.10.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0d7ba649cf0d796247840c87e216ea37727b43073f35533cbfdf3cca539776f |
|
MD5 | 37d739789efaa0f9c913fb0335b12862 |
|
BLAKE2b-256 | d316aadd0d8e812ad2d7711c86d3648c034ca82517c4a160c04402f98c165555 |
File details
Details for the file numpyslicesplit-0.10-py3-none-any.whl
.
File metadata
- Download URL: numpyslicesplit-0.10-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 721c6c2b63d4dfdc7ab981911e03d6c51825832222100e12ea8dc720982f5a8a |
|
MD5 | efa9fb1537cee7435197ef2bc19d4ecd |
|
BLAKE2b-256 | fb41c9a3cf6384f609ae5dec855509613edad8c162c3f4eaa10e039c4d1dc77e |