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.5.tar.gz (4.7 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.5-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyarrlib-0.1.5.tar.gz
  • Upload date:
  • Size: 4.7 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.5.tar.gz
Algorithm Hash digest
SHA256 751f833c60e3fff7b6c136118f7bf8ecef62cf06d6d3b879fd2a17a5962fcd58
MD5 c961a3c9849e32b94f9924e7968183e0
BLAKE2b-256 8283ebcd279eae507ab5fd366fe70daa392eb4d183cc0630577fc5e11e31b190

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyarrlib-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b34ca576468415893d91926a1eebd7ba8b2daed0b70334fd4e598de4d8828d9c
MD5 a20ff8ef6bd89debe132a1af14a2bbec
BLAKE2b-256 038c1c9ae346b6723030de7dbc8e0d70618e4b33d7a21d70dac99a9ca9df202c

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