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>

<pre><code>arr=np.array(y_pred_list)  #list to narray
arr[arr&lt;0.5]=0             #  arr&lt;0.5 is a mask narray 
arr[arr&gt;=0.5]=1
y_pred_list=arr.tolist()   # narray to list
</code></pre>

python arrays list numpy