this module can help you work with arrays
Project description
pyarrlib
A small Python utility library for working with arrays and nested array structures.
This project provides simple helper functions for reversing arrays, computing numeric aggregates, and traversing nested sequences to count or flatten leaf values.
Features
reverse_arr(array): reverse a sequencesum_arr(array): compute the sum of numeric valuesmultiplication_arr(array): compute the product of numeric valuesleafs(array): flatten nested integer arraysnum_of_leafs(array): count integer leaf nodes in nested arrayslen_arr(array): count all scalar leaves in nested arrays
Installation
From the repository root, install in editable mode:
python -m pip install -e .
If you prefer not to install, you can run code directly from this project by ensuring the repository root is on PYTHONPATH.
Usage
from scr import reverse_arr, sum_arr, multiplication_arr, leafs, num_of_leafs, len_arr, ArrayTypeError
print(reverse_arr([1, 'hello', 3, True]))
# [True, 3, 'hello', 1]
print(sum_arr([1, 5, 4, 3, 8]))
# 21
print(multiplication_arr([4, 1, 2, 5, 7]))
# 280
nested = [[1, 2, [3]], [4, [5, 6]]]
print(leafs(nested))
# [1, 2, 3, 4, 5, 6]
print(num_of_leafs(nested))
# 6
print(len_arr(nested))
# 6
API Reference
reverse_arr(array)
Return a new sequence with the elements in reverse order.
sum_arr(array)
Return the sum of numeric values in the array.
If a non-numeric element is encountered, the function returns the sentinel class ArrayTypeError.
multiplication_arr(array)
Return the product of numeric values in the array.
If a non-numeric element is found, the function returns ArrayTypeError.
leafs(array)
Return a flat list containing all integer leaf values from a nested array structure.
num_of_leafs(array)
Count integer leaf nodes recursively in a nested array structure.
len_arr(array)
Count all scalar leaf values in a nested array structure. Supported scalar types include int, str, float, and bool.
Running the included checks
The repository includes a simple assertion-based test file.
python tests/test.py
Project structure
pyproject.toml– package metadata and build configurationREADME.md– project documentationscr/arrpy.py– array utility functions and error typescr/multidim_arr.py– nested array traversal functionstests/test.py– example assertions covering core behavior
License
This project is licensed under MIT.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyattlib-0.1.1.tar.gz.
File metadata
- Download URL: pyattlib-0.1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.15.0a5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d8114252ddcd9680e13f8d552a14b889b179287ff3d20694f11d4d9cacae746
|
|
| MD5 |
6c60e40dbc503214089ba097d5c5ea02
|
|
| BLAKE2b-256 |
d6bdaf6629176c43385d63bc43cd05ce04bbe3392d56b7a742d3ae7906f8c66c
|
File details
Details for the file pyattlib-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyattlib-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.15.0a5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deb25d11284bac3450ef2a7528da0d5e544d61ec0bd9ddfa2848aa52d17022b6
|
|
| MD5 |
068d2e14c6748bb85f8195d74ddf38c8
|
|
| BLAKE2b-256 |
2e144208120322ddd12d8782ed3446fd90e606a07b2272a5b9b4e1b747cbda41
|