擅长:python、mysql、java
<p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfile.html" rel="nofollow">^{<cd1>}</a>有一个<code>sep=</code>关键字参数:</p>
<blockquote>
<p>Separator between items if file is a text file. Empty (“”) separator means the file should be treated as binary. Spaces (” ”) in the separator match zero or more whitespace characters. A separator consisting only of spaces must match at least one whitespace.</p>
</blockquote>
<p>默认值<code>sep=""</code>表示<code>np.fromfile()</code>尝试将其读取为二进制文件,而不是空格分隔的文本文件,因此会返回无意义的值。如果你使用<code>np.fromfile('markers.txt', sep=" ")</code>,你会得到你想要的结果。</p>
<p>然而,正如其他人指出的,<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html#numpy.loadtxt" rel="nofollow">^{<cd6>}</a>是将文本文件转换为numpy数组的首选方法,除非该文件需要人类可读,否则通常最好使用二进制格式(例如<code>np.load()</code>/<code>np.save()</code>)。</p>