python - 如何将数字 numpy 数组更改为 char 数组?
问题描述
我想使用 python 将数字 numpy 数组更改为 char 数组,例如,
a = np.arange(25).reshape([5,5])
如何将数组 a 更改为 char 数组?
解决方案
您可以使用方法更改 numpy 数组的数据类型astype
。试试下面的例子:
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
推荐阅读
- excel - 如何在excel中计算日期时间之间的差异
- sql - 当 T-SQL 中的另一行 <> 'X' 时,检索具有最近日期的一行数据
- c# - 从 C# 中的 WebSocket 流中读取整个字符串
- c++ - 在这种情况下如何使用线程?
- rstudio - 如何在 R 的进一步分析中避免行名?
- xpath - 使用python为HTML树中的已知元素自动生成XPath
- shell - 如何使用`sys.args`在命令linux中为文件python执行转义`()`?
- c# - C#如何在另一个类obj中初始化一个类obj的数组?
- android - 在使用 net::ERR_FILE_NOT_FOUND 成功上传后,使用 Ionic4 和 Angular HttpClient 上传分块文件失败
- c - 在函数内部如何检查边缘是否存在,以便在 C 中不会重新插入边缘