0

I have a sets of numpy arrays which I create using

for longtuple in itertools.product([0,1], repeat = n + m -1 ):
    outputs = set(np.convolve(v, longtuple, 'valid').tostring() for v in itertools.product([0,1], repeat = m))
    if (len(outputs) == 2**m):
        print "Hooray!"

However I would actually like to take every element x of np.convolve(v, longtuple, 'valid') and apply x >> k & 1 (for values of k that I will specify) and then add that resulting array to the set instead. Is there an efficient way to do this?


My use of set and tostring() is simply to see if there are any duplicates. I am not sure it is correct however.

2
  • just be aware that for example -0. and 0. are different in this sense... Commented Mar 6, 2014 at 13:26
  • @seberg Oh! Which test makes them the same? Commented Mar 6, 2014 at 18:23

1 Answer 1

1

You can just take the result of convolve and apply your expression to it:

set((np.convolve(v, longtuple, 'valid') >> k & 1).tostring() for v in itertools.product([0,1], repeat = m))
Sign up to request clarification or add additional context in comments.

2 Comments

I am worried my use of tostring() is wrong. I am only using it so I can add the arrays to the set. But it doesn't make sense to do >> k & 1 after calling tostring() does it?
Sorry, I messed it up. See my edited answer. You want to do >> k & 1 on the result of convolve, then apply tostring after that.

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.