Get a row, a range of rows or a slice from the array. The set of tokens allowed for the key is the same as that for extended slicing in Python (including the Ellipsis or ... token). The result is an object of the current flavor; its shape depends on the kind of slice
(self, key: SelectionType)
| 633 | return selection, reorder, mshape |
| 634 | |
| 635 | def __getitem__(self, key: SelectionType) -> list | np.ndarray: |
| 636 | """Get a row, a range of rows or a slice from the array. |
| 637 | |
| 638 | The set of tokens allowed for the key is the same as that for extended |
| 639 | slicing in Python (including the Ellipsis or ... token). The result is |
| 640 | an object of the current flavor; its shape depends on the kind of slice |
| 641 | used as key and the shape of the array itself. |
| 642 | |
| 643 | Furthermore, NumPy-style fancy indexing, where a list of indices in a |
| 644 | certain axis is specified, is also supported. Note that only one list |
| 645 | per selection is supported right now. Finally, NumPy-style point and |
| 646 | boolean selections are supported as well. |
| 647 | |
| 648 | Examples |
| 649 | -------- |
| 650 | :: |
| 651 | |
| 652 | array1 = array[4] # simple selection |
| 653 | array2 = array[4:1000:2] # slice selection |
| 654 | array3 = array[1, ..., ::2, 1:4, 4:] # general slice selection |
| 655 | array4 = array[1, [1,5,10], ..., -1] # fancy selection |
| 656 | array5 = array[np.where(array[:] > 4)] # point selection |
| 657 | array6 = array[array[:] > 4] # boolean selection |
| 658 | |
| 659 | """ |
| 660 | self._g_check_open() |
| 661 | |
| 662 | try: |
| 663 | # First, try with a regular selection |
| 664 | startl, stopl, stepl, shape = self._interpret_indexing(key) |
| 665 | arr = self._read_slice(startl, stopl, stepl, shape) |
| 666 | except TypeError: |
| 667 | # Then, try with a point-wise selection |
| 668 | try: |
| 669 | coords = self._point_selection(key) |
| 670 | arr = self._read_coords(coords) |
| 671 | except TypeError: |
| 672 | # Finally, try with a fancy selection |
| 673 | selection, reorder, shape = self._fancy_selection(key) |
| 674 | arr = self._read_selection(selection, reorder, shape) |
| 675 | |
| 676 | if self.flavor == "numpy" or not self._v_convert: |
| 677 | return arr |
| 678 | |
| 679 | return internal_to_flavor(arr, self.flavor) |
| 680 | |
| 681 | def __setitem__(self, key: SelectionType, value: Any) -> None: |
| 682 | """Set a row, a range of rows or a slice in the array. |
nothing calls this directly
no test coverage detected