this module can help you work with arrays
Project description
pyarrlib
A small Python utility library for working with arrays and nested nested array structures.
This project provides simple helper functions for reversing arrays, computing numeric aggregates, counting nested leaves, flattening nested structures, and solving small systems of linear equations.
Features
reverse_arr(array)— reverse a one-dimensional sequencesum_arr(array)— compute the sum of numeric valuesmultiplication_arr(array)— compute the product of numeric valuesmin(array)— find the smallest numeric value in a sequencemax(array)— find the largest numeric value in a sequencearifmetic_mean(array)— compute the arithmetic mean 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 arraysequation_system(full_matrix)— solve 2×2 or 3×3 linear systems using determinants
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 (
ArrayTypeError,
arifmetic_mean,
equation_system,
leafs,
len_arr,
max,
min,
multiplication_arr,
num_of_leafs,
reverse_arr,
sum_arr,
)
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
print(min([1, 3, 6, -3, 2]))
# -3
print(arifmetic_mean([2, 4, 6]))
# 4.0
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
system = [
[2, -1, 1],
[1, 1, 1],
[1, 2, -1],
]
print(equation_system([row + [value] for row, value in zip(system, [1, 2, 3])]))
API Reference
ArrayTypeError
A sentinel error type used by numeric functions when an array contains unsupported element types.
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 the array contains a non-numeric element, the function returns the class ArrayTypeError.
multiplication_arr(array)
Return the product of numeric values in the array.
If the array contains a non-numeric element, the function returns ArrayTypeError.
min(array)
Return the smallest value from a one-dimensional sequence.
max(array)
Return the largest value from a one-dimensional sequence.
arifmetic_mean(array)
Return the arithmetic mean of numeric values in the array.
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.
equation_system(full_matrix)
Solve a 2×2 or 3×3 system of linear equations supplied as an augmented matrix.
The function returns a list of solution values or the string "has no solution" when the determinant is zero.
Running the included checks
The repository includes a simple assertion-based test file.
python tests/test.py
Project structure
setup.py— 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 pyarrlib-0.1.2.tar.gz.
File metadata
- Download URL: pyarrlib-0.1.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.15.0a5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b01b95d51f9c053006251847a1b91d43c9d31bd77a39044cfda8623da34df20
|
|
| MD5 |
e8531d348305e6a3a3a5541fd396321e
|
|
| BLAKE2b-256 |
0ceadce10d4758ffb625d30d6c8b53e5fdc62f89753f49d33d09c2f38a87ba94
|
File details
Details for the file pyarrlib-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pyarrlib-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.6 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 |
f5d6dee0cb1d03b073c8f6d6dd1186720be218801c5a338c907c68a294808fc7
|
|
| MD5 |
54eac8e220c8cf4b91804d99b3367cce
|
|
| BLAKE2b-256 |
b5e537bb1ec66f28ae50d73685bde408918af066c3d928466cc727f400a4b639
|