from itertools import product
p = np.random.randint(1,2,2)
p = product(p, repeat=50)
I don't know how to get length of P immediately
from itertools import product
p = np.random.randint(1,2,2)
p = product(p, repeat=50)
I don't know how to get length of P immediately
This is simple combinatorics, not really programming. There are a**n
ways to select any of a
values n
times (repetition is allowed). In your case, a
is len(p)
(the original p
, the array), or 2 (since you've generated an array with two values), and n
is 50, so will get 2**50
or 1125899906842624 results from your product
if you have a whole lot of time to iterate over them all.
Now, if you're looking for how many distinct values you get, the answer is even easier (though subtly so). There's only one distinct value ever generated, a tuple with 50 ones. That's because you're taking products from an array that contains only the value 1
, never anything else, since numpy.random.randint(1, 2)
only ever gives you 1
(the upper bound is excluded).
The product iterator will have as many items as the lengths of all iterables you pass in multiplied with each other.
You're passing in one iterable but repeating it 50 times. Therefore you have to multiply the length of p
50 times with each other. That's basically len(p)**50
.