I am creating symmetric matrices/arrays in Python with NumPy, using a standard method:
x = rand(500,500)
x = (x+x.T)
all(x==x.T)
> True
The problem is that the addition is not done "at once"; x.T
is a view of the x
so as you start adding to each element of x
, x.T
is mutated. This messes up later additions.
The fact it works for sizes below (91, 91)
is almost definitely an implementation detail. Using
x = numpy.random.rand(1000, 1000)
x += x.T.copy()
numpy.all(x==x.T)
#>>> True
fixes that, but then you don't really have any space-benefit.