MCPcopy Create free account
hub / github.com/numpy/numpy / SubArray

Class SubArray

numpy/ma/tests/test_subclassing.py:23–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 assert_equal(a[:len(b)], b)
22
23class SubArray(np.ndarray):
24 # Defines a generic np.ndarray subclass, that stores some metadata
25 # in the dictionary `info`.
26 def __new__(cls,arr,info={}):
27 x = np.asanyarray(arr).view(cls)
28 x.info = info.copy()
29 return x
30
31 def __array_finalize__(self, obj):
32 super().__array_finalize__(obj)
33 self.info = getattr(obj, 'info', {}).copy()
34 return
35
36 def __add__(self, other):
37 result = super().__add__(other)
38 result.info['added'] = result.info.get('added', 0) + 1
39 return result
40
41 def __iadd__(self, other):
42 result = super().__iadd__(other)
43 result.info['iadded'] = result.info.get('iadded', 0) + 1
44 return result
45
46
47subarray = SubArray

Callers 4

__new__Method · 0.85
test_data_subclassingMethod · 0.85
test_subclass_reprMethod · 0.85
test_subclass_strMethod · 0.85

Calls

no outgoing calls

Tested by 4

__new__Method · 0.68
test_data_subclassingMethod · 0.68
test_subclass_reprMethod · 0.68
test_subclass_strMethod · 0.68