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)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章