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.2.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for arrayclasses-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51bda5dfcbd5db699622879a9350a41f56ef774bb05e1e8641a4c0f982b780c7 |
|
MD5 | a61c97e3e4f2920b3721b49f43441fc5 |
|
BLAKE2b-256 | 0098034768cc8620f6a248964c31eb7ad526ed220e18e52029ceaa448ac0043f |