Skip to content

Instantly share code, notes, and snippets.

@mocquin
Last active June 27, 2021 17:10
Show Gist options
  • Save mocquin/fbe0010a4b02ff0e4000ba933b2c8464 to your computer and use it in GitHub Desktop.
Save mocquin/fbe0010a4b02ff0e4000ba933b2c8464 to your computer and use it in GitHub Desktop.
numpy_w
import numpy as np
class Physical():
def __init__(self, value, unit=""):
self.value = value # store the numerical value as a plain numpy array
self.unit = unit
def __repr__(self):
return f"<Physical:({self.value}, {self.unit})"
def __str__(self):
return f"{self.value} {self.unit}"
weights = Physical(np.array([55.6, 45.7, 80.3]), "kilogram")
print(weights) # [55.6 45.7 80.3] kilogram
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment