Replacing Elements in 3 dimensional Python List
<p>I've a Python list if converted to NumPy array would have the following dimensions: (5, 47151, 10)</p>

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

len(y_pred_list)
# returns 5
</code></pre>

<p>I would like to go through every element and replace the element where:</p>

<ul>
<li>If the element >= 0.5 then 1.</li>
<li>If the element &lt; 0.5 then 0.</li>
</ul>

<p>Any idea? </p>

<p>To create an array with a value True if the element is >= 0.5, and False otherwise:</p>

<pre><code>new_array = y_pred_list &gt;= 0.5
</code></pre>

<p>use the .astype() method for Numpy arrays to make all True elements 1 and all False elements 0:</p>

<pre><code>new_array.astype(int)
</code></pre>

python arrays list numpy