title: How do I extract the lower/upper triangle of a non-square numpy array?
body: <p>So basically I have an array <strong>subslope</strong> consisting of the following:</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  slp = 1501.66*(np.ones((1000,1000), dtype=np.float32))
  vsub = 2000*(np.ones((1000,1000), dtype=np.float32))
  
  slope = np.triu(slp)
  slope2 = np.tril(vsub, k=-1)
  subslope = slope + slope2
  </code></pre>
  <p>This is the visual representation:</p>
  <p><a href="https://i.stack.imgur.com/acjO6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/acjO6.png" alt="enter image description here" /></a></p>
  <p>You can see the diagonal separating two parts of the array, the upper part has values of 1501.66 and 2000 below the diagonal. However, when I change the dimensions such that the number of columns is significantly larger than the number of rows like this:</p>
  <pre><code>slp = 1501.66*(np.ones((1000,2000), dtype=np.float32))
  vsub = 2000*(np.ones((1000,2000), dtype=np.float32))
  </code></pre>
  <p>We get the following:</p>
  <p><a href="https://i.stack.imgur.com/J04WP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J04WP.png" alt="enter image description here" /></a></p>
  <p>What I want is the diagonal to run from the top corner of the array to the bottom corner like this:</p>
  <p><a href="https://i.stack.imgur.com/Ctxhk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ctxhk.png" alt="enter image description here" /></a></p>
  <p>How can I achieve this?</p>