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)
Built Distribution
Close
Hashes for arrayclasses-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 554b463a4190d76f348fb235262b97c565f8105ea58aff4ae6f37f2036dcb293 |
|
MD5 | 96238ad4c2525018a062f011937fe003 |
|
BLAKE2b-256 | 964a26cfdd5522bd60bc450a0aff8b3d3d061cfd897edbf0bf97fa6cb361dd8e |