如何将数字numpy数组更改为char数组?

时间:2018-10-17 04:05:54

标签: python numpy

例如,我想使用python将数字numpy数组更改为char数组,

a = np.arange(25).reshape([5,5])

如何将数组a更改为char数组?

1 个答案:

答案 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