例如,我想使用python将数字numpy数组更改为char数组,
a = np.arange(25).reshape([5,5])
如何将数组a更改为char数组?
答案 0 :(得分:3)
您可以使用astype
方法来更改numpy数组的数据类型。请尝试以下示例:
import numpy as np
a = np.arange(25).reshape([5,5])
a.dtype #check data type of array it should show int
new = a.astype(str) #change data type of array to string
new.dtype #Check the data type again it should show string