为numpy.array

时间:2019-12-04 22:56:57

标签: python arrays python-3.x numpy dtype

当我尝试设置dtype的{​​{1}}时遇到字符串变空的问题。

numpy.array

提供以下数组,其中字符串import numpy as np data = [('peter', 182.37), ('parker', 179.24)] arr = np.array(data, dtype=np.dtype([('name', np.unicode), ('height', np.float16)])) print(arr) 'peter'现在都为'parker'

  

[('',182.4)('',179.2)]

如果未指定dtype,则字符串将按预期出现在''中。

np.array
  

[['peter''182.37']

     

['parker''179.24']]

问题::当字符串的dtype为import numpy as np data = [('peter', 182.37), ('parker', 179.24)] arr = np.array(data) print(arr) np.unicode时,为什么字符串会变为空? np.string的字符串dtype必须支持可变长度的字符串。我们该如何解决?谢谢!

使用 Python 3.7.4,numpy 1.17.2

0 个答案:

没有答案