title: Transforming a list containing the elements below the diagonal of a matrix into a full matrix
body: <p>I want to create a full-fledged matrix from a list of the elements that are below the diagonal. The following list contains the elements below the diagonal:
  <a href="https://i.stack.imgur.com/DGpch.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DGpch.png" alt="enter image description here" /></a></p>
  <p>And this would be the desired output:</p>
  <p><a href="https://i.stack.imgur.com/LzQ4Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LzQ4Y.png" alt="enter image description here" /></a></p>
  <p>Up until this point, I tried to make this work with normal sintax in python by implementing the following code:</p>
  <pre><code>list_similarities = [1,0.1,0.6,0.4,1,0.1,0.2,1,0.7,1]
  
  the_range = range(0,4)
  
  list_of_lists = []
  counter_element = 0
  counter = -1
  for element in the_range:
      counter += 1
      counter_element += len(the_range)-element
      intermediary = (len(the_range)-element)
      first_element = counter_element-intermediary
      line_list = list_similarities[first_element:counter_element]
      # counter = 0, then no need to add an additional element
      # print(line_list)
      if counter == 0:
          &quot;do nothing&quot;
      elif counter &gt;0:
          for item in range(0,element):
              from_list_to_add = list_of_lists[item]
              element_to_add = from_list_to_add[item+1]
              line_list.insert(0,element_to_add)
      print(line_list)
      list_of_lists.append(line_list.copy())
      # print(&quot;final lists:&quot;, list_of_lists)
  
  
  # print(counter_element)
  print(&quot;final lists:&quot;, list_of_lists)
  </code></pre>
  <p>However, the output is the following:</p>
  <blockquote>
  <p>final lists: [[1, 0.1, 0.6, 0.4], [0.1, 1, 0.1, 0.2], [0.1, 0.1, 1, 0.7], [0.7, 0.1, 0.1, 1]]</p>
  </blockquote>
  <p>It does the first 2 lists, which represent the 2 rows from the matrix, but will not do the last 2 because of the way my code works and so far I don't know a solution for that..</p>
  <p>This is due to the fact that my counter will make the list go out of range. I looked at a lot of posts on the stack overflow, but I cannot find something that would work in my situation. If you can point me towards a similar example it would be perfect.</p>
  <p>Thank you for your time and suggestions!</p>
  <p><strong>UPDATE :</strong>
  My question is not a duplicate of <a href="https://stackoverflow.com/questions/20055493/numpy-convert-an-array-to-a-triangular-matrix">Numpy: convert an array to a triangular matrix</a> because I do not want to create a matrix where my values from the array are part of just the lower triangular matrix, but rather they are also in the upper triangular matrix.</p>