Issue
Is there any syntax in python to create range
with condition ?
For example:
in range(101, 9999999999999999999999999999999999999999999)
count all numbers, divisible by 11
. Iterating over all range like
len([i for i in range(101, 9999999999999999999999999999999999999999999) if % 11 = 0])
is very slow. I tried to do vectorization filtering on numpy array
np.arange(101, 9999999999999999999999999999999999999999999, dtype=np.int8)
but numpy throws
Maximum allowed size exceeded
So my guess is to initially do not include do not dividable numbers in range. Is there any way to do it in range
function ?
Solution
Any number that is divisible by 11 would be starting at the first number after your starting index that can be divided by 11 (which should be quick to find: s_idx + 11 - s_idx % 11
should work), and then using the step
parameter to range
to move 11 each time.
range(start, end, 11)
Answered By - MatsLindh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.