Skip to main content

Analogue to dataclass that uses a numpy-backed array to store values.

Project description

arrayclass

A small @dataclass-like decorator for python classes. The class will store its values in a single contiguous numpy array. It can also be converted to and from plain numpy arrays.

Installation

poetry add dataclasses or pip install dataclasses

Usage

import arrayclasses

@arrayclasses.arrayclass
class State:
    x: float
    y: tuple[float, float]
    z: float

# Object creation
state = State(x=5, y=(0, 1), z=0)
print(np.x)  # Prints 5.0
print(np.y)  # Prints np.array([0.0, 1.0])
state.y = 2.0
print(np.y)  # Prints np.array([2.0, 2.0])

# Array conversion.
state = arrayclasses.from_array((5, 0, 1, 0))
print(np.array(state))  # prints np.array([5.0, 0.0, 1.0, 0.0])

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

arrayclasses-0.1.1.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

arrayclasses-0.1.1-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

Supported by

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