MCPcopy Index your code
hub / github.com/numpy/numpy / container

Class container

numpy/lib/_user_array_impl.py:43–287  ·  view source on GitHub ↗

container(data, dtype=None, copy=True) Standard container-class for easy multiple-inheritance. Methods ------- copy byteswap astype

Source from the content-addressed store, hash-verified

41
42@set_module("numpy.lib.user_array")
43class container:
44 """
45 container(data, dtype=None, copy=True)
46
47 Standard container-class for easy multiple-inheritance.
48
49 Methods
50 -------
51 copy
52 byteswap
53 astype
54
55 """
56 def __init_subclass__(cls) -> None:
57 # Deprecated in NumPy 2.4, 2025-11-24
58 import warnings
59
60 warnings.warn(
61 "The numpy.lib.user_array.container class is deprecated and will be "
62 "removed in a future version.",
63 DeprecationWarning,
64 stacklevel=2,
65 )
66
67 def __init__(self, data, dtype=None, copy=True):
68 self.array = array(data, dtype, copy=copy)
69
70 def __repr__(self):
71 if self.ndim > 0:
72 return self.__class__.__name__ + repr(self.array)[len("array"):]
73 else:
74 return self.__class__.__name__ + "(" + repr(self.array) + ")"
75
76 def __array__(self, t=None):
77 if t:
78 return self.array.astype(t)
79 return self.array
80
81 # Array as sequence
82 def __len__(self):
83 return len(self.array)
84
85 def __getitem__(self, index):
86 return self._rc(self.array[index])
87
88 def __setitem__(self, index, value):
89 self.array[index] = asarray(value, self.dtype)
90
91 def __abs__(self):
92 return self._rc(absolute(self.array))
93
94 def __neg__(self):
95 return self._rc(-self.array)
96
97 def __add__(self, other):
98 return self._rc(self.array + asarray(other))
99
100 __radd__ = __add__

Callers 2

lib_user_array.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…