I am trying to generate a matrix A == [f(i,j) for i,j in range(0,n)]
. The matrix is symmetric (f(i,j) == f(j,i))
and the diagonal elements are zero (f(i,i) == 0)
.
Question: Is it possible to produce a list comprehension that generates this matrix but that only calls the function f(i,j)
for i < j
?
Not my question: Generate the symmetric matrix in some other way.
Possible solution: Make the call to f
through an auxiliary function g
that saves the value of f
in an additional storage or returns the stored value.
Would it be possible to solve avoiding the additional storage? I am not sure if this additional handicap implies that a reference to the list comprehension from itself (which I read doesn't exist in Python) is necessary, hopefully I am missing some other trick.