Pad one `axis` of `arr` with the maximum of the last `num` elements. Parameters ---------- arr : ndarray Input array of arbitrary shape. pad_amt : int Amount of padding to append. num : int Depth into `arr` along `axis` to calculate maximum.
(arr, pad_amt, num, axis=-1)
| 365 | |
| 366 | |
| 367 | def _append_max(arr, pad_amt, num, axis=-1): |
| 368 | """ |
| 369 | Pad one `axis` of `arr` with the maximum of the last `num` elements. |
| 370 | |
| 371 | Parameters |
| 372 | ---------- |
| 373 | arr : ndarray |
| 374 | Input array of arbitrary shape. |
| 375 | pad_amt : int |
| 376 | Amount of padding to append. |
| 377 | num : int |
| 378 | Depth into `arr` along `axis` to calculate maximum. |
| 379 | Range: [1, `arr.shape[axis]`] or None (entire axis) |
| 380 | axis : int |
| 381 | Axis along which to pad `arr`. |
| 382 | |
| 383 | Returns |
| 384 | ------- |
| 385 | padarr : ndarray |
| 386 | Output array, with `pad_amt` values appended along `axis`. The |
| 387 | appended region is the maximum of the final `num` values along `axis`. |
| 388 | |
| 389 | """ |
| 390 | if pad_amt == 0: |
| 391 | return arr |
| 392 | |
| 393 | # Equivalent to edge padding for single value, so do that instead |
| 394 | if num == 1: |
| 395 | return _append_edge(arr, pad_amt, axis) |
| 396 | |
| 397 | # Use entire array if `num` is too large |
| 398 | if num is not None: |
| 399 | if num >= arr.shape[axis]: |
| 400 | num = None |
| 401 | |
| 402 | # Slice a chunk from the edge to calculate stats on |
| 403 | if num is not None: |
| 404 | max_slice = _slice_last(arr.shape, num, axis=axis) |
| 405 | else: |
| 406 | max_slice = tuple(slice(None) for x in arr.shape) |
| 407 | |
| 408 | # Extract slice, calculate max |
| 409 | max_chunk = arr[max_slice].max(axis=axis, keepdims=True) |
| 410 | |
| 411 | # Concatenate `arr` with `max_chunk`, extended along `axis` by `pad_amt` |
| 412 | return _do_append(arr, max_chunk.repeat(pad_amt, axis=axis), axis) |
| 413 | |
| 414 | |
| 415 | def _prepend_mean(arr, pad_amt, num, axis=-1): |
no test coverage detected