I have an array arr in which I would like to zero the interval (over the last dim) around every max value.
Here's what I'm generally trying to do (this code doesn't work):
assume that interval_size is some positive odd integer.
argmax = np.argmax(arr, axis=-1)

half_interval = (interval_size - 1) // 2  # assume the interval is of odd size
left_index = argmax - half_interval
right_index = argmax + half_interval
# fix overflow
left_index[left_index < 0] = 0
right_index[right_index >= arr.shape[-1]] = arr.shape[-1] - 1

# this is just illustrative and doesn't work:
arr[left_index:right_index] = 0  # zero the interval in-place


Numpy interval of indices around max value on the last dimension
Given that the intervals could be different sizes, I'd go for boolean indexing:
import numpy as np

arr = np.random.randint(10, size=(8, 8))
half_interval = 2

# Use keepdims=True for easy broadcasting
argmax = arr.argmax(axis=-1, keepdims=True)

# "Normal" indices for the last axis
idx = np.arange(arr.shape[-1])

# True when "normal" index is between
# [argmax - half_interval, argmax + half_interval]
mask = (argmax - half_interval <= idx) & (idx <= argmax + half_interval)

arr[mask] = 0
# or out = np.where(mask, 0, arr) if you don't want to modify arr

Results:
>>> arr
array([[6, 8, 5, 4, 6, 9, 3, 6],
       [9, 4, 9, 3, 9, 0, 3, 6],
       [7, 9, 7, 1, 0, 3, 0, 0],
       [9, 9, 4, 8, 3, 8, 3, 2],
       [9, 7, 6, 9, 2, 0, 9, 6],
       [1, 7, 9, 7, 6, 2, 9, 4],
       [8, 0, 8, 9, 6, 5, 0, 9],
       [2, 0, 9, 5, 9, 0, 2, 4]])
>>> argmax
array([[5],
       [0],
       [1],
       [0],
       [0],
       [2],
       [3],
       [2]], dtype=int64)
>>> mask
array([[False, False, False,  True,  True,  True,  True,  True],
       [ True,  True,  True, False, False, False, False, False],
       [ True,  True,  True,  True, False, False, False, False],
       [ True,  True,  True, False, False, False, False, False],
       [ True,  True,  True, False, False, False, False, False],
       [ True,  True,  True,  True,  True, False, False, False],
       [False,  True,  True,  True,  True,  True, False, False],
       [ True,  True,  True,  True,  True, False, False, False]])
>>> out
array([[6, 8, 5, 0, 0, 0, 0, 0],
       [0, 0, 0, 3, 9, 0, 3, 6],
       [0, 0, 0, 0, 0, 3, 0, 0],
       [0, 0, 0, 8, 3, 8, 3, 2],
       [0, 0, 0, 9, 2, 0, 9, 6],
       [0, 0, 0, 0, 0, 2, 9, 4],
       [8, 0, 0, 0, 0, 0, 0, 9],
       [0, 0, 0, 0, 0, 0, 2, 4]])

The above should work for arrays with more than 2 axes as well due to broadcasting. But only because you argmax over the final axis.
