Created
November 7, 2015 14:18
-
-
Save avamsi/046014d466b3b140d982 to your computer and use it in GitHub Desktop.
Prime Sieve with numpy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy | |
| prime = numpy.ones(limit/2, dtype=numpy.bool) | |
| for i in xrange(3, int(limit**.5) + 1, 2): | |
| if prime[i/2]: | |
| prime[i*i/2: : i] = False | |
| primes = 2*prime.nonzero()[0] + 1 | |
| primes[0] = 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment