title: Fast diagonal matrix creation from two lists
body: <p>Given 2 lists I would like to create a <code>Diagonal matrix</code>. <br>
  One list will fill the <code>diagonal-constant</code> and the other will fill the matrix.</p>
  
  <p>For example:</p>
  
  <p><code>fast_matrix([1,2], [6,7,8])</code></p>
  
  <p>Should output 2 matrices:</p>
  
  <pre><code>[2] # unused
  [1, 6, 7, 8]
  [6, 1, 7, 8]
  [6, 7, 1, 8]
  [6, 7, 8, 1]
  </code></pre>
  
  <p>and </p>
  
  <pre><code>[1] # unused
  [2, 6, 7, 8]
  [6, 2, 7, 8]
  [6, 7, 2, 8]
  [6, 7, 8, 2]
  </code></pre>
  
  <p>My <a href="https://repl.it/repls/DeliciousOrdinaryCharacter" rel="nofollow noreferrer">code makes 10000 transformations</a> in 2.5secs in my pc.</p>
  
  <pre><code>from pprint import pprint
  import timeit
  
  def not_so_fast_matrix(A, B):
      rt_obj = []
      for i,_ in enumerate(A):
          for z in range(len(B) + 1):
              new_from = A.copy()
              new_from.remove(A[i])
              new_list = B.copy()
              new_list.insert(z, A[i])
              rt_obj.append({'remain': new_from, 'to_list': new_list})
      return rt_obj
  
  # pprint(not_so_fast_matrix([1,2], [6,7,8]))
  
  A = ([1,2,3,4,5,6,7,8,9,10])
  B = ([60,70,80,90,100,200,300])
  t = timeit.Timer(lambda: not_so_fast_toeplitz(A, B))
  print("not_so_fast_matrix took: {:.3f}secs for 10000 iterations".format(t.timeit(number=10000)))
  </code></pre>
  
  <p>I was wondering if it can go faster using another approach.
  <hr>
  <code>Circulant</code> from <code>scipy.linalg</code> looks like what I'm after but without rolling:</p>
  
  <pre><code>from scipy.linalg import circulant
  
  print(circulant([1, 8,7,6])) # &lt;- Should be inverted
  outputs:
  [[1 6 7 8]
   [8 1 6 7]
   [7 8 1 6]
   [6 7 8 1]]
  </code></pre>
  
  <p>Elements were shifted (pushed) right.</p>