list - Trying to find all combinations of a 2-state vector (in python) -
i trying find combinations of 4 element vector contains 1's , -1's. ex (1,1,1,1),(-1,1,1,1),...(-1,-1,-1,-1) etc idea pretty inefficient im sure can't think of way it, here trying do. found how many total vectors there be, created many empty lists. began vector a
, compared each list in vectors
. if a
matched of lists randomly changed sign of element of a
, , again checked new list a
against vectors
. if a
didn't find match replaced on of lists in vectors
, , while loop incremented 1. should proceed until possible combinations have been found , printed. code spitting out first change in vectors
continually looping without adding new a
's vectors
. can spot in code isn't doing intended and/or point me in right direction? thanks
import random numvec = 2**4 # number of macrostates 4 component 2-state system vectors = [[0,0,0,0] in range(numvec)] #initializing numvec vectors = [1,1,1,1] = 0 while < 16: if any(x == x in vectors): y = random.randrange(0, 3) a[y] = a[y] * -1 else: vectors[i] = print vectors[i] += 1 print vectors
oh , again realize method incredibly inefficient homework assignment more concerned being able python want do, using bunch of built in functions work me. again.
vectors[i] =
this doesn't create copy of a
. when change a
, contents of vectors
change, because vectors[0]
, a
same object after first time line runs. fix this, make new a
object every time, or copy a
, insert copy list.
if want make copy, can use python's slice notation:
vectors[i] = a[:]
Comments
Post a Comment