python中ndarray如何生成单独的记事本文件_如何将numpy ndarray保存为.csv文件?

我创建了一个numpy数组,如下所示:import numpy as np

names = np.array(['NAME_1', 'NAME_2', 'NAME_3'])

floats = np.array([ 0.1234 , 0.5678 , 0.9123 ])

ab = np.zeros(names.size, dtype=[('var1', 'U6'), ('var2', float)])

ab['var1'] = names

ab['var2'] = floats

ab中的值如下所示:

^{pr2}$

当我试图使用savetxt()命令将ab保存为.csv文件时np.savetxt('D:\test.csv',ab,delimiter=',')

我得到下面的错误---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

in ()

----> 1 np.savetxt('D:\Azim\JF-Mapping-workflow-CRM\Backup\delete.csv',ab,delimiter=',')

c:\python27\lib\site-packages\numpy\lib\npyio.pyc in savetxt(fname, X, fmt, delimiter, newline, header, footer, comments)

1256 raise TypeError("Mismatch between array dtype ('%s') and "

1257 "format specifier ('%s')"

-> 1258 % (str(X.dtype), format))

1259 if len(footer) > 0:

1260 footer = footer.replace('\n', '\n' + comments)

TypeError: Mismatch between array dtype ('[('var1', '

你可能感兴趣的:(python中ndarray如何生成单独的记事本文件_如何将numpy ndarray保存为.csv文件?)