如何将数字数组改为字符数组?

2024-04-25 13:04:45 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

如何更改数组?在


Tags: numpynp数组chararangereshape
1条回答
网友
1楼 · 发布于 2024-04-25 13:04:45

您可以使用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

相关问题 更多 >