Attain a tally of a column of a 2d array
<p>I have a 2d array data. And would like to attain a tally every time the jth iteration is a 1.
Where i = rows and j = columns. 
How do I go about doing this without a for loop? </p>

<p>Conceptually something like this:</p>

<pre><code>for r in range(row):
    if(data[r][j] == 1)
        amount += 1
</code></pre>

<p>You can do as follow:</p>

<pre><code>import numpy as np
a = np.array([[0, 1], [1, 1]])
j = 1
np.sum(a[:, j] == 1)
</code></pre>

<p>will give you 2 as a result
, while <code>np.sum(a[:, 0] == 1)</code> will give 1</p>

<p>If as mentioned in your comment you want to use a condition on multiple arrays, you can use <code>np.logical_and(condition1, condition2)</code>:</p>

<pre><code>np.sum(np.logical_and(a[:, 0] == 1, b[:, 0] == 2))
</code></pre>

python arrays numpy multidimensional-array scipy