import numpy as np
a = np.array([2, 0, 0, 0, 0])
idx = np.argmax(a) if ~np.all(a == a[0]) else None
print(idx) # 0
b = np.array([0, 0, 0, 0, 0])
idx = np.argmax(b) if ~np.all(b == b[0]) else None
print(idx) # None
# Alternative solution
a = np.array([2, 0, 0, 0, 0])
idx = np.argmax(a) - np.all(a == a[0]).astype(int)
print(idx) # 0
b = np.array([0, 0, 0, 0, 0])
idx = np.argmax(b) - np.all(b == b[0]).astype(int)
print(idx) # -1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…