I suppose I should wait until you edit the question, but I went ahead and looked at the figure. It looks like a symmetric matrix based on tri-upper and lower matrices. In what dicispline is that called a `full matrix'?
Anyhow's here one sequence that produces your figure:
In [93]: idx=np.tril_indices(4)
In [94]: idx
Out[94]: (array([0, 1, 1, 2, 2, 2, 3, 3, 3, 3]), array([0, 0, 1, 0, 1, 2, 0, 1, 2, 3]))
In [95]: arr = np.zeros((4,4),int)
In [96]: arr[idx] = np.arange(1,11)
In [97]: arr
Out[97]:
array([[ 1, 0, 0, 0],
[ 2, 3, 0, 0],
[ 4, 5, 6, 0],
[ 7, 8, 9, 10]])
In [98]: arr1 = arr + arr.T
In [99]: arr1
Out[99]:
array([[ 2, 2, 4, 7],
[ 2, 6, 5, 8],
[ 4, 5, 12, 9],
[ 7, 8, 9, 20]])
In [100]: dx = np.diag_indices(4)
In [101]: dx
Out[101]: (array([0, 1, 2, 3]), array([0, 1, 2, 3]))
In [102]: arr1[dx] = arr[dx]
In [103]: arr1
Out[103]:
array([[ 1, 2, 4, 7],
[ 2, 3, 5, 8],
[ 4, 5, 6, 9],
[ 7, 8, 9, 10]])
This is similar to what scipy.spatial
calls a squareform
for pairwise distances.
https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.spatial.distance.squareform.html#scipy.spatial.distance.squareform
In [106]: from scipy.spatial import distance
In [107]: distance.squareform(np.arange(1,11))
Out[107]:
array([[ 0, 1, 2, 3, 4],
[ 1, 0, 5, 6, 7],
[ 2, 5, 0, 8, 9],
[ 3, 6, 8, 0, 10],
[ 4, 7, 9, 10, 0]])
It appears that this square_form
uses compiled code, so I expect it will be quite a bit faster than my tril
base code. But the order of elements isn't quite what you expect.