将菜鸟教程中“NumPy数据类型”实例8的’abc’改为中文字符时,运行报错,例如:
import numpy as np
student = np.dtype([('name',"S20"), ('age', 'i1'), ('marks', 'f4')])
a = np.array([('一', 21, 50),('xyz', 18, 75)], dtype = student)
print(a)
将"S20"改为"U32"即可解决
import numpy as np
student = np.dtype([('name',"U32"), ('age', 'i1'), ('marks', 'f4')])
a = np.array([('一', 21, 50),('xyz', 18, 75)], dtype = student)
print(a)