Skip to main content

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 sequence
  • sum_arr(array) — compute the sum of numeric values
  • multiplication_arr(array) — compute the product of numeric values
  • min(array) — find the smallest numeric value in a sequence
  • max(array) — find the largest numeric value in a sequence
  • arifmetic_mean(array) — compute the arithmetic mean of numeric values
  • leafs(array) — flatten nested integer arrays
  • num_of_leafs(array) — count integer leaf nodes in nested arrays
  • len_arr(array) — count all scalar leaves in nested arrays
  • equation_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 configuration
  • README.md — project documentation
  • scr/arrpy.py — array utility functions and error type
  • scr/multidim_arr.py — nested array traversal functions
  • tests/test.py — example assertions covering core behavior

License

This project is licensed under MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyarrlib-0.1.7.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyarrlib-0.1.7-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pyarrlib-0.1.7.tar.gz.

File metadata

  • Download URL: pyarrlib-0.1.7.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.15.0a5

File hashes

Hashes for pyarrlib-0.1.7.tar.gz
Algorithm Hash digest
SHA256 951abf8035c85b49ae63bd02c994edca54ba93569535e7781853dd18bf14484e
MD5 facc74d04e120a4f04d14a24c7f17a28
BLAKE2b-256 33e633f78c52ee07bde4fea4151d03191fd3b1c8d6990a23aa82b370cfee3d63

See more details on using hashes here.

File details

Details for the file pyarrlib-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: pyarrlib-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.15.0a5

File hashes

Hashes for pyarrlib-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8d57ddca42cec06c05e2d9b18f3ea48b8cf1d151b0a42ec0d6b07718e72d3d02
MD5 d1de25bb12388b689e3e93845d9aacf6
BLAKE2b-256 b02a415edc4717c38ccd3ec695b1014391c96f5e13948df88277b03ac67f275a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page