title: Checking elements in a matrix in python
body: <p>I have a matrix in scipy. And I'm trying to replace it with a 1 if it meets a certain condition, and a 0 if it doesnt.</p>
  
  <pre><code>for a in range(0,l):
        for b in range(0,l):
                 if Matrix[a][b] == value:
                      Matrix[a][b] = 1
                 else:
                      Matrix[a][b] = 0
  </code></pre>
  
  <p>My matrix is full of elements that have the "value" in it. Yet it's giving me the output as a matrix that is entirely 0's.</p>
  
  <p>This worked before on a similar script. Is it perhaps something to with the structure of the matrix?</p>
  
  <p>Here's how the matrix looks at first--</p>
  
  <pre><code>[ [0   1.  1.  2.]
    [1.  0.  2.  1.]
    [1.  2.  0.  1.]
    [2.  1.  1.  0.]]
  </code></pre>
  
  <p>When i set value == 1. I get all the 1's to 1's, and all the 2's to zero. Which is what I want.</p>
  
  <p>But, when i set value == 2. I get everything to zero.</p>
  
  <p>when I do all of what has been suggested.</p>
  
  <pre><code>[[ 0.  1.  1.  2.  1.  2.  2.  3.]
   [ 1.  0.  2.  1.  2.  1.  3.  2.]
   [ 1.  2.  0.  1.  2.  3.  1.  2.]
   [ 2.  1.  1.  0.  3.  2.  2.  1.]
   [ 1.  2.  2.  3.  0.  1.  1.  2.]
   [ 2.  1.  3.  2.  1.  0.  2.  1.]
   [ 2.  3.  1.  2.  1.  2.  0.  1.]
   [ 3.  2.  2.  1.  2.  1.  1.  0.]]
  
  &gt;&gt;  np.where(matrix==2,1,0)
  &gt;&gt; array([[0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0]])
  </code></pre>