Reflect boundaries of array on the same side This is the converse of ``periodic``
(x, axis, depth)
| 217 | |
| 218 | |
| 219 | def reflect(x, axis, depth): |
| 220 | """Reflect boundaries of array on the same side |
| 221 | |
| 222 | This is the converse of ``periodic`` |
| 223 | """ |
| 224 | if depth == 1: |
| 225 | left = ( |
| 226 | (slice(None, None, None),) * axis |
| 227 | + (slice(0, 1),) |
| 228 | + (slice(None, None, None),) * (x.ndim - axis - 1) |
| 229 | ) |
| 230 | else: |
| 231 | left = ( |
| 232 | (slice(None, None, None),) * axis |
| 233 | + (slice(depth - 1, None, -1),) |
| 234 | + (slice(None, None, None),) * (x.ndim - axis - 1) |
| 235 | ) |
| 236 | right = ( |
| 237 | (slice(None, None, None),) * axis |
| 238 | + (slice(-1, -depth - 1, -1),) |
| 239 | + (slice(None, None, None),) * (x.ndim - axis - 1) |
| 240 | ) |
| 241 | l = x[left] |
| 242 | r = x[right] |
| 243 | |
| 244 | l, r = _remove_overlap_boundaries(l, r, axis, depth) |
| 245 | |
| 246 | return concatenate([l, x, r], axis=axis) |
| 247 | |
| 248 | |
| 249 | def nearest(x, axis, depth): |