title: Easy way to set elements in top 0.005% of an array to 1 and the rest to zero
body: <p>`  </p>
  
  <pre><code>thoughtx=frame[:,:thought1.shape[1]]
  
  
  thiss=thoughtx.flatten()
  index=heapq.nlargest(round(0.005*256*144*3),thiss )
  thoughtx.shape=(1,256,144,3)
  </code></pre>
  
  <p>`i am looking for an efficient way to select all the elements of an 4D  array within the top 0.005% in value and replace them with ones while simultaneously converting the rest of the entries to zero's?</p>
  
  <p>I have tried using nlargest above but it seems to return a list. i was hoping it would return a soft copy of the original array and then i would modify it by proxy.</p>