Eigen: how can I substitute matrix positive values with 1 and 0 otherwise?
<p>I want to write the following matlab code in <code>Eigen</code> (where <code>K</code> is <code>pxp</code> and <code>W</code> is <code>pxb</code>):</p>

<pre><code>H = (K*W)&gt;0;
</code></pre>

<p>However the only thing that I came up so far is:</p>

<pre><code>H = ((K*W.array() &gt; 0).select(1,0)); 
</code></pre>

<p>This code doesn't work as explained <a href="https://stackoverflow.com/questions/21440511/strange-behavior-of-eigenselect">here</a>, but replacing <code>0</code> with <code>VectorXd::Constant(p,0)</code> (as suggested in the link question) generates a runtime error:</p>

<pre><code>Eigen::internal::variable_if_dynamic&lt;T, Value&gt;::variable_if_dynamic(T) [with T = long int; int Value = 1]: Assertion `v == T(Value)' failed.
</code></pre>

<p>How can I solve this?</p>