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=())
| 367 | |
| 368 | |
| 369 | def _leading_trailing(a, edgeitems, index=()): |
| 370 | """ |
| 371 | Keep only the N-D corners (leading and trailing edges) of an array. |
| 372 | |
| 373 | Should be passed a base-class ndarray, since it makes no guarantees about |
| 374 | preserving subclasses. |
| 375 | """ |
| 376 | axis = len(index) |
| 377 | if axis == a.ndim: |
| 378 | return a[index] |
| 379 | |
| 380 | if a.shape[axis] > 2*edgeitems: |
| 381 | return concatenate(( |
| 382 | _leading_trailing(a, edgeitems, index + np.index_exp[ :edgeitems]), |
| 383 | _leading_trailing(a, edgeitems, index + np.index_exp[-edgeitems:]) |
| 384 | ), axis=axis) |
| 385 | else: |
| 386 | return _leading_trailing(a, edgeitems, index + np.index_exp[:]) |
| 387 | |
| 388 | |
| 389 | def _object_format(o): |
no test coverage detected