Следующий код делает то, что я хочу :
Код: Выделить всё
import numpy as np
def isValid(np_shape: tuple, index: tuple):
if min(index) < 0:
return False
for ind,sh in zip(index,np_shape):
if ind >= sh:
return False
return True
arr = np.zeros((3,5))
print(isValid(arr.shape,(0,0))) # True
print(isValid(arr.shape,(2,4))) # True
print(isValid(arr.shape,(4,4))) # False
Подробнее здесь: https://stackoverflow.com/questions/744 ... umpy-array
Мобильная версия