Return a new arrayterator.
(self, index)
| 93 | return getattr(self.var, attr) |
| 94 | |
| 95 | def __getitem__(self, index): |
| 96 | """ |
| 97 | Return a new arrayterator. |
| 98 | |
| 99 | """ |
| 100 | # Fix index, handling ellipsis and incomplete slices. |
| 101 | if not isinstance(index, tuple): |
| 102 | index = (index,) |
| 103 | fixed = [] |
| 104 | length, dims = len(index), self.ndim |
| 105 | for slice_ in index: |
| 106 | if slice_ is Ellipsis: |
| 107 | fixed.extend([slice(None)] * (dims-length+1)) |
| 108 | length = len(fixed) |
| 109 | elif isinstance(slice_, int): |
| 110 | fixed.append(slice(slice_, slice_+1, 1)) |
| 111 | else: |
| 112 | fixed.append(slice_) |
| 113 | index = tuple(fixed) |
| 114 | if len(index) < dims: |
| 115 | index += (slice(None),) * (dims-len(index)) |
| 116 | |
| 117 | # Return a new arrayterator object. |
| 118 | out = self.__class__(self.var, self.buf_size) |
| 119 | for i, (start, stop, step, slice_) in enumerate( |
| 120 | zip(self.start, self.stop, self.step, index)): |
| 121 | out.start[i] = start + (slice_.start or 0) |
| 122 | out.step[i] = step * (slice_.step or 1) |
| 123 | out.stop[i] = start + (slice_.stop or stop-start) |
| 124 | out.stop[i] = min(stop, out.stop[i]) |
| 125 | return out |
| 126 | |
| 127 | def __array__(self): |
| 128 | """ |