How to apply bitwise operator to compare a list of objects
<p>Suppose I have a long list of objects (say, a list of numpy matrices of bool elements) <code>foo = [a, b, c]</code>, that I want to compare with some bitwise operator, to get something like <code>a | b | c</code>.</p>

<p>If I could use this bitwise operation as a function, say a <code>bitwiseor</code> function, I could simply do this with <code>bitwiseor(*foo)</code>.
However, I was not able to find whether the bitwise or can be written in such functional form.</p>

<p>Is there some handy way to handle this kind of problem? Or should I just use a loop to compare all the elements cumulatively?</p>

<p><code>numpy</code> has a number of functions that support reducing along an axis.  See <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.bitwise_or.html#numpy.bitwise_or" rel="nofollow"><code>numpy.bitwise_or</code></a> and <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.reduce.html#numpy.ufunc.reduce" rel="nofollow"><code>numpy.bitwise_or.reduce</code></a>.</p>

<pre><code>np.bitwise_or.reduce(your_array)
</code></pre>

python bitwise-operators