>>> import numpy as np
>>> a = np.array(['zero', 'one', 'two', 'three'])
>>> a[1] = 'thirteen'
>>> print a
['zero' 'thirt' 'two' 'three']
>>>
Run Code Online (Sandbox Code Playgroud)
如您所见,第二个元素已被截断为原始数组中的最大字符数.
有可能解决这个问题吗?
如果您不知道最大长度元素,则可以使用dtype = object
>>> import numpy as np
>>> a = np.array(['zero', 'one', 'two', 'three'], dtype=object)
>>> a[1] = 'thirteen'
>>> print a
['zero' 'thirteen' 'two' 'three']
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
945 次 |
| 最近记录: |