python - 无法更改 numpy 数组中字符串的大小
问题描述
我在更改存储在 NumPy 数组中的字符串的大小时遇到问题。例如,我将图像的路径存储在一个数组中,并使用“replace”函数将末尾的“.png”替换为“ something .png”。但是发生的情况是该操作仅将新字符串保持在字符串的原始长度,不会添加任何额外的内容。
- E:\Thesis Data\2018-weedMap-dataset-release\Tiles\RedEdge\000\groundtruth\000_frame0000.png
- E:\Thesis Data\2018-weedMap-dataset-release\Tiles\RedEdge\000\groundtruth\000_frame0000_und
1:原始字符串 2:替换字符串
正如在上面的字符串中看到的那样,我用“_underground.png”替换了“.png”,但它只保留了“_und”,它等于我要替换的字符串的长度,即“.png”。
解决方案
So your sample string(s) is 91 char long, consistent with the '<U91' dtype. You can't increase that without making a new array with a longer dtype.
In [11]: ''' 1. E:\Thesis
...: Data\2018-weedMap-dataset-release\Tiles\RedEdge\000\groundtruth\000_frame0000.
...: png '''
Out[11]: ' 1. E:\\Thesis\n Data\x818-weedMap-dataset-release\\Tiles\\RedEdge\x00\\groundtruth\x00_frame0000.png '
In [12]: len(_)
Out[12]: 91
推荐阅读
- nagios - Nagios 不发送服务警报
- statistics - 样本量的正确计算方法是什么?
- javascript - Jquery Json Array 响应未在 Div 中打印
- laravel - 从用户模型获取数据 - 显示错误 -> 此集合实例上不存在属性 [名称]
- reactjs - toast 编辑器 getHTML() 最大堆栈错误
- java - Spring Boot mutlimodule 项目的依赖子模块中的应用程序上下文为空
- youtube-api - Youtube Data API search.list 直播流出现故障
- javascript - 当页面仅通过悬停href链接预加载时阻止javascript执行
- python - 如何将 singledispatchmethod 与继承类一起使用
- oracle - 在 oracle 10G 中将列转换为行