<p>您可以将<a href="https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.loadtxt.html" rel="nofollow noreferrer">unpack</a>参数添加到<code>numpy.loadtxt()</code>。然后可以<a href="https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.transpose.html" rel="nofollow noreferrer">numpy.transpose()</a>新创建的numpy数组以获得所需的数组形状。你知道吗</p>
<pre><code>import numpy as np
dattyp = [('sex',object),('length',float),('diameter',float),('height',float),('whole weight',float),('shucked weight',float),('viscera weight',float),('shell weight',float),('rings',int)]
abalone_data = np.loadtxt('C:/path/abalone.dat',dtype = dattyp, delimiter = ',', unpack=True)
abalone_data = np.array((abalone_data)).transpose()
print(abalone_data.shape)
</code></pre>
<p><strong>输出:</strong></p>
<pre><code>(4177, 9)
</code></pre>
<p><strong>来自文档:</strong></p>
<blockquote>
<p>unpack : bool, optional</p>
<p>If True, the returned array is transposed, so that arguments may be
unpacked using x, y, z = loadtxt(...). When used with a structured
data-type, arrays are returned for each field. Default is False.</p>
</blockquote>