<p>似乎您只是想将文本数据转换为<code>numpy</code><code>array</code>。正如@BiRico所指出的,在一个<code>array</code>中不能有多个数据类型<code>dtype</code>,如果必须这样做,就必须使用<code>strutured array</code>,或者更好的方法是使用<code>pandas</code>数据帧。你知道吗</p>
<p>而且<code>numpy</code>有构建IO函数<code>genfromtxt()</code>,速度非常快。使用它而不是硬代码1:</p>
<pre><code>>>> dtypeLS=[('Var0', 'S10'),
('Var1', 'S10'),
('Var2', 'f8'),
('Var3', '<M8[D]'),
('Var4', 'f8'),
('Var5', 'f8'),
('Var6', '<M8[D]'),
('Var7', 'f8'),
('Var8', 'f8'),
('Var9', 'f8'),
('Var10', 'f8'),
('Var11', 'f8'),
('Var12', 'f8'),
('Var13', 'f8'),
('Var14', 'f8'),
('Var15', 'f8'),
('Var16', 'f8'),
('Var17', 'f8'),
('Var18', 'f8'),
('Var19', 'f8'),
('Var20', 'f8'),
('Var21', 'f8'),
('Var22', 'f8'),
('Var23', 'f8'),
('Var24', 'f8'),
('Var25', 'f8'),
('Var26', 'f8'),
('Var27', 'f8'),
('Var28', 'f8'),
('Var29', 'f8'),
('Var30', 'f8'),
('Var31', 'f8'),
('Var32', 'S10'),
('Var33', 'f8'),
('Var34', 'f8'),
('Var35', 'f8'),
('Var36', 'f8'),
('Var37', 'f8'),
('Var38', 'f8')]
>>> a=genfromtxt('temp.txt', dtype=dtypeLS)
>>> a[0]
('TRE-G3T-', 'Triumph-', 0.0, datetime.date(2013, 10, 1), 227001.3, 1760.0, datetime.date(2013, 10, 1), 227016.3, 41.0, 31.0, 27.35998, -70.0, 40.0, 19.00843, -28.13, 0.707, 882922.244, 2652775.212, -65.517, -24.677, -13.47, 0.02, 0.022, 0.041, 0.051, -13.469, -0.771, 0.0109, 2.0, 1.8, 7.0, 0.005, 'S', 0.032, -0.024, 0.001, -0.256, -0.162, 0.554)
>>> a['Var11']
array([-70., -70., -70., -70., -70.])
>>> a['Var12']
array([ 40., 40., 40., 40., 40.])
>>> a['Var13']
array([ 19.00843, 19.00854, 19.00848, 19.00858, 19.00849])
>>> np.sign(a['Var11'])*(np.abs(a['Var11'])+a['Var12']/60+a['Var13']/3600)
array([-70.67194679, -70.67194682, -70.6719468 , -70.67194683, -70.6719468 ])
</code></pre>
<p>最后,就像在<code>Matlab</code>中一样,如果您想让事情快速运行,请始终进行矢量化。请参阅最后一行中的dd到dms转换代码。你知道吗</p>
<p>另外,我必须将您的日格式从<code>10-01-2013</code>更改为<code>2013-10-01</code>,以使用<code>datetime</code><code>dtype</code>。你知道吗</p>