title: Generating Symmetric Matrices in Numpy
body: <p>I am trying to generate symmetric matrices in numpy. Specifically, these matrices are to have random places entries, and in each entry the contents can be random. Along the main diagonal we are not concerned with what entries are in there, so I have randomized those as well.</p>
  <p>The approach I have taken is to first generate a nxn all zero matrix and simply loop over the indices of the matrices.
  How can I do this more efficiently using numpy?</p>
  <pre><code>import numpy as np
  import random
  
  def empty(x, y):
      return x*0
  
  b = np.fromfunction(empty, (n, n), dtype = int)
  
  for i in range(0, n):
      for j in range(0, n):
          if i == j:
              b[i][j] = random.randrange(-2000, 2000)
          else:
              switch = random.random()
              random.seed()
              if switch &gt; random.random():
                  a = random.randrange(-2000, 2000)
                  b[i][j] = a
                  b[j][i] = a
              else:
                  b[i][j] = 0
                  b[j][i] = 0
  </code></pre>