title: Using a lambda function in np.fromfunction with an if statement depending on `i` and `j`
body: <p>I do not know how to insert the <code>if</code> statement <code>if (i + j) % 2 == 0</code> into a lambda function. It is not as straightforward as a single variable.</p>
  <p>Here is my attempt</p>
  <pre><code># dummy values
  two_at = 4.5 
  n = 5
  m = 6
  # fromfunction with lambda function
  matrix = np.fromfunction(lambda i, j: 1 / (two_at) ** ((i+j)/2) if (i+j) % 2 == 0 else 0.0, (n+1, m+1))
  </code></pre>
  <p>The error I get is</p>
  <p><code>matrix = np.fromfunction(lambda i, j: 1 / (two_at) ** ((i+j)/2) if (i+j) % 2 == 0 else 0.0, (n + 1, m + 1)) </code>
  <code>ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()</code></p>
  <p>I would be more than satisfied with any answer that is faster than a double for loop such as</p>
  <pre><code>   matrix = np.zeros((n,m))
     for i in range(n + 1):
         for j in range(m + 1):
             m = i + j
             if m % 2 == 0:
                 matrix[i,j] = 1 / (two_at) ** (m/2) 
  </code></pre>