解决Numpy 报错 ValueError: zero-size array to reduction operation maximum which has no identity

这是因为numpy对一个空的array做运算操作造成的,如:

x = np.array([])
# x + 1 # 会报错

建议在代码中可以改为:

if x.size == 0:
    print('x.size is 0')
else:
    print('x.size > 0')

你可能感兴趣的:(python,numpy)