MCPcopy Create free account
hub / github.com/ahalev/python-microgrid / NDArraySubclass

Class NDArraySubclass

src/pymgrid/utils/serialize.py:125–138  ·  view source on GitHub ↗

A simple python class that allows a 'path' attribute for serialization. `path` may be lost if object is manipulated.

Source from the content-addressed store, hash-verified

123
124
125class NDArraySubclass(np.ndarray):
126 """
127 A simple python class that allows a 'path' attribute for serialization.
128 `path` may be lost if object is manipulated.
129 """
130 def __new__(cls, input_array, path=None):
131 obj = np.asarray(input_array).view(cls)
132 obj.path = path
133 return obj
134
135 def __array_finalize__(self, obj):
136 if obj is None:
137 return
138 self.path = getattr(obj, 'path', None)

Callers 1

add_path_to_arr_likeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected