擅长:python、mysql、java
<p>知道您的数据在<code>dtype</code>中是非常重要的,但是如果它是<code>float</code>或{<cd3>}或者{<cd1>}s之类的任何一个数字,<code>boolean</code>索引就足够了</p>
<p>数据文件:</p>
<pre><code><temp.txt>
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 bad
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 bad
1 2 3 4 5 6
1 2 3 4 5 6
</code></pre>
<p>解决方案:</p>
^{pr2}$
<h2>编辑</h2>
<p>如果<code>array</code>已经在<code>string</code>中,这可能是最简单的:</p>
<pre><code>In [40]:
%%file temp.txt
1000.00 200.00
4000.00 adfdfddfds
20.00 5000
text_ok_here 5000
Overwriting temp.txt
In [53]:
A=np.genfromtxt('temp.txt', dtype=str)
B=np.genfromtxt('temp.txt')
In [55]:
A[np.isfinite(B[:,1])]
Out[55]:
array([['1000.00', '200.00'],
['20.00', '5000'],
['text_ok_here', '5000']],
dtype='|S12')
</code></pre>
<p>基本上,将数据读入<code>A</code>,作为<code>string</code>s的<code>array</code>;读入<code>B</code>中<code>float</code>和{<cd13>}中,然后根据<code>B</code>得到{<cd8>}的一部分。在</p>