Comparing Arrays for Accuracy
<p>I've a 2 arrays:</p>

<pre><code>np.array(y_pred_list).shape
# returns (5, 47151, 10)
np.array(y_val_lst).shape
# returns (5, 47151, 10)

np.array(y_pred_list)[:, 2, :]
# returns 
array([[ 0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])

np.array(y_val_lst)[:, 2, :]
# returns
array([[ 0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]], dtype=float32)
</code></pre>

<p>I would like to go through all 47151 examples, and calculate the "accuracy". Meaning the sum of those in y_pred_list that matches y_val_lst over 47151. What's the comparison function for this? </p>

<p>Sounds like you want something like this:</p>

<pre><code>accuracy = (y_pred_list == y_val_lst).all(axis=(0,2)).mean()
</code></pre>

<p>...though since your arrays are clearly floating-point arrays, you might want to allow for numerical-precision errors rather than insisting on exact equality:</p>

<pre><code>accuracy = (numpy.abs(y_pred_list - y_val_lst) &lt; tolerance ).all(axis=(0,2)).mean()
</code></pre>

<p>(where, for example, <code>tolerance = 1e-10</code>)</p>

<p>The <code>.all(axis=(0,2))</code> call records cases in which everything in its input is <code>True</code> (i.e. everything matches) when working along the dimension 0 (i.e. the one that has extent 5) and dimension 2 (the one that has extent 10). It outputs a one-dimensional array of length 47151.  The <code>.mean()</code> call then gives you the proportion of matches in that sequence, which is my best guess as to what you mean by "over 47151".</p>

python arrays numpy