python numpy.float类型转int类型报错TypeError: only size-1 arrays can be converted to Python scalars

a = np.array([1.0, 2.0])
np.int(a)

使用np.int(a)会报错TypeError: only size-1 arrays can be converted to Python scalars

解决办法:

1.改为np.int0(), np.int32(),np.int64(),np.intp(), n.int_()

2.改为a.astype(np.int)

你可能感兴趣的:(python numpy.float类型转int类型报错TypeError: only size-1 arrays can be converted to Python scalars)