擅长:python、mysql、java
<p>管理非重叠功能的解决方案。在</p>
<pre><code>def count(row,mins):
runs=(row!=0).astype(uint8).tobytes().decode().split(chr(0))
lengths=[len(run) for run in runs]
return np.floor_divide.outer(lengths,mins).sum(0)
</code></pre>
<p>它使用strings-fast操作来查找所有的运行,然后使用//来查找每个给定长度的不重叠的运行数。在</p>
<p>使用<code>df:</code></p>
^{pr2}$
<p><code>np.apply_along_axis(count,1,df,[2,3,4])</code>返回</p>
<pre><code>array([[1, 0, 0],
[1, 0, 0],
[2, 1, 1],
[1, 1, 0]], dtype=int32)
</code></pre>
<p>这是<code>df</code>的预期结果。在</p>