I have a simple piece of code which doesn't run as expected.
from numpy import *
from numpy.linalg import *
from sets import Set
W = matrix('1, 1, 1, 1; 1, 1, -1, -1; 1, -1, 2, -2; 1, -1, -2, 2')
E = matrix('1, 1, 1, 1; 1, 1, -1, -1; 1, -1, 2, -2; 1, -1, -2, 2')
matrices = Set([])
matrices.add(W)
matrices.add(E)
matrices
The matrices are identical, however they both appear seperately when I print the contents of the set. However, if I assign it like below, then the duplicate does not appear.
W = matrix('1, 1, 1, 1; 1, 1, -1, -1; 1, -1, 2, -2; 1, -1, -2, 2')
E = W
Any idea what is happening? I need a way of avoiding duplicate matrices in a program I am writing, which generates a tonne of matrices.
EDIT: I want the following output
set([matrix([[ 1, 1, 1, 1],
[ 1, 1, -1, -1],
[ 1, -1, 2, -2],
[ 1, -1, -2, 2]])])
but instead get the following:
set([matrix([[ 1, 1, 1, 1],
[ 1, 1, -1, -1],
[ 1, -1, 2, -2],
[ 1, -1, -2, 2]]), matrix([[ 1, 1, 1, 1],
[ 1, 1, -1, -1],
[ 1, -1, 2, -2],
[ 1, -1, -2, 2]])])