Keep only the N-D corners (leading and trailing edges) of an array. Should be passed a base-class ndarray, since it makes no guarantees about preserving subclasses.
(a, edgeitems, index=())
| 436 | |
| 437 | |
| 438 | def _leading_trailing(a, edgeitems, index=()): |
| 439 | """ |
| 440 | Keep only the N-D corners (leading and trailing edges) of an array. |
| 441 | |
| 442 | Should be passed a base-class ndarray, since it makes no guarantees about |
| 443 | preserving subclasses. |
| 444 | """ |
| 445 | axis = len(index) |
| 446 | if axis == a.ndim: |
| 447 | return a[index] |
| 448 | |
| 449 | if a.shape[axis] > 2 * edgeitems: |
| 450 | return concatenate(( |
| 451 | _leading_trailing(a, edgeitems, index + np.index_exp[:edgeitems]), |
| 452 | _leading_trailing(a, edgeitems, index + np.index_exp[-edgeitems:]) |
| 453 | ), axis=axis) |
| 454 | else: |
| 455 | return _leading_trailing(a, edgeitems, index + np.index_exp[:]) |
| 456 | |
| 457 | |
| 458 | def _object_format(o): |
no test coverage detected
searching dependent graphs…