container(data, dtype=None, copy=True) Standard container-class for easy multiple-inheritance. Methods ------- copy tostring byteswap astype
| 14 | |
| 15 | |
| 16 | class container: |
| 17 | """ |
| 18 | container(data, dtype=None, copy=True) |
| 19 | |
| 20 | Standard container-class for easy multiple-inheritance. |
| 21 | |
| 22 | Methods |
| 23 | ------- |
| 24 | copy |
| 25 | tostring |
| 26 | byteswap |
| 27 | astype |
| 28 | |
| 29 | """ |
| 30 | def __init__(self, data, dtype=None, copy=True): |
| 31 | self.array = array(data, dtype, copy=copy) |
| 32 | |
| 33 | def __repr__(self): |
| 34 | if self.ndim > 0: |
| 35 | return self.__class__.__name__ + repr(self.array)[len("array"):] |
| 36 | else: |
| 37 | return self.__class__.__name__ + "(" + repr(self.array) + ")" |
| 38 | |
| 39 | def __array__(self, t=None): |
| 40 | if t: |
| 41 | return self.array.astype(t) |
| 42 | return self.array |
| 43 | |
| 44 | # Array as sequence |
| 45 | def __len__(self): |
| 46 | return len(self.array) |
| 47 | |
| 48 | def __getitem__(self, index): |
| 49 | return self._rc(self.array[index]) |
| 50 | |
| 51 | def __setitem__(self, index, value): |
| 52 | self.array[index] = asarray(value, self.dtype) |
| 53 | |
| 54 | def __abs__(self): |
| 55 | return self._rc(absolute(self.array)) |
| 56 | |
| 57 | def __neg__(self): |
| 58 | return self._rc(-self.array) |
| 59 | |
| 60 | def __add__(self, other): |
| 61 | return self._rc(self.array + asarray(other)) |
| 62 | |
| 63 | __radd__ = __add__ |
| 64 | |
| 65 | def __iadd__(self, other): |
| 66 | add(self.array, other, self.array) |
| 67 | return self |
| 68 | |
| 69 | def __sub__(self, other): |
| 70 | return self._rc(self.array - asarray(other)) |
| 71 | |
| 72 | def __rsub__(self, other): |
| 73 | return self._rc(asarray(other) - self.array) |