0

I have binary vectors X1 through X6 and Y1 through Y6. I want to find the outer product between each vector in X and its corresponding vector in Y, e.g. outer product of (X1,Y1) , outer product of (X2,Y2) and so on. I am using numpy.outer(X1, Y1). Now I want to generate a for loop to go through all of them and then OR their outputs together. Below is my code I get the error "SyntaxError: can't assign to operator" when I remove the %d beside the w on the LHS of the equation I get another error that X isn't defined. So, can anybody help me on how to solve this 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)

for i in range (1, 6):
    w%d=np.outer(X%d,Y%d) % (i, i, i)
    wt=wt or w%d % i
print wt

Thanks

3
  • Can you add your expected output to question? Commented May 31, 2015 at 23:18
  • what did you expect w%d=np.outer(X%d,Y%d) % (i, i, i) to do exactly? Commented May 31, 2015 at 23:28
  • 1st iteration:, 'w1=np.outer(X1,Y1)', 'wt = wt or w1', 2nd iteration:, 'w2=np.outer(X2,Y2)', 'wt= wt or w2', and so on. Commented Jun 1, 2015 at 1:12

1 Answer 1

1

You might want to put your variables in an array:

X = [X1, X2, ..., X6]
Y = [Y1, Y2, ..., Y6]

That way:

W = [np.outer(x, y) for (x,y) in zip(X,Y)]
wt = reduce(lambda a,b: a or b,
            W,
            np.zeros((5,5),dtype=np.integer))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, however, I get the error "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.