Assign control variables in for loop python -
i have binary vectors x1 through x6 , y1 through y6. want find outer product between each vector in x , corresponding vector in y, e.g. outer product of (x1,y1) , outer product of (x2,y2) , on. using numpy.outer(x1, y1). want generate loop go through of them , or outputs together. below code error "syntaxerror: can't assign operator" when remove %d beside w on lhs of equation error x isn't defined. so, can me on how solve issue.
x1=[1, 0, 0, 1, 0] x2=[0, 0, 0, 1, 1] x3=[1, 0, 1, 0, 0] x4=[1, 0, 0, 0, 1] x5=[1, 1, 0, 0, 0] x6=[0, 1, 0, 1, 0] y1=[[1], [0], [0], [0], [0]] y2=[[0], [0], [1], [0], [0]] y3=[[0], [1], [0], [0], [0]] y4=[[0], [0], [0], [1], [0]] y5=[[0], [0], [0], [0], [1]] y6=[[0], [0], [0], [1], [0]] w=(5,5) wt= np.zeros((w),dtype=np.integer) in range (1, 6): w%d=np.outer(x%d,y%d) % (i, i, i) wt=wt or w%d % print wt
thanks
you might want put variables in array:
x = [x1, x2, ..., x6] y = [y1, y2, ..., y6]
that way:
w = [np.outer(x, y) (x,y) in zip(x,y)] wt = reduce(lambda a,b: or b, w, np.zeros((5,5),dtype=np.integer))
Comments
Post a Comment