Skip to content

Instantly share code, notes, and snippets.

@asosnovsky
Created August 27, 2019 21:17
Show Gist options
  • Save asosnovsky/8eb38ec46c1281bdc55f279800a66cc9 to your computer and use it in GitHub Desktop.
Save asosnovsky/8eb38ec46c1281bdc55f279800a66cc9 to your computer and use it in GitHub Desktop.
import numpy as np
def dtype(cls):
dt = np.dtype([n for n in cls.__annotations__.items()])
def new(*args) -> np.ndarray:
return np.array(list(args), dtype=dt)
return new
@dtype
class Point:
x: np.float32
y: np.float32
Point( (2, 2) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment