Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy primes

import numpy
def primesfrom2to(n):
    """ Input n>=6, Returns a array of primes, 2 <= p < n """
    sieve = numpy.ones(n//3 + (n%6==2), dtype=bool)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[       k*k//3     ::2*k] = False
            sieve[k*(k-2*(i&1)+4)//3::2*k] = False
    return numpy.r_[2,3,((3*numpy.nonzero(sieve)[0][1:]+1)|1)]
Comment

numpy primes

import numpy
def primesfrom2to(n):
    """ Input n>=6, Returns a array of primes, 2 <= p < n """
    sieve = numpy.ones(n//3 + (n%6==2), dtype=bool)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[       k*k//3     ::2*k] = False
            sieve[k*(k-2*(i&1)+4)//3::2*k] = False
    return numpy.r_[2,3,((3*numpy.nonzero(sieve)[0][1:]+1)|1)]
Comment

PREVIOUS NEXT
Code Example
Python :: root = tk() python 3 
Python :: theme_use() tkinter theme usage 
Python :: states and capitals us comma separated list 
Python :: looping over dictionary python 
Python :: .corr() python 
Python :: random forest classifier classification report 
Python :: python code for binary search tree 
Python :: change folder name python 
Python :: python selenium: does not wait until page is loaded after a click() command 
Python :: python generator function 
Python :: python csv find specific string 
Python :: logging python 
Python :: how to run mac terminal from python script 
Python :: using csv module how to read perticular lines in csv 
Python :: matplotlib colormap transparent white to black 
Python :: os module 
Python :: pandas include nan in value_counts 
Python :: decorators in python 
Python :: requirements.txt dev python 
Python :: image data generator tensorflow 
Python :: np.random.randint to generate -1 +1 
Python :: python default value 
Python :: python generate tuple from lists 
Python :: open file in os python 
Python :: |= operator python 
Python :: python how to invert an array 
Python :: using hashlib module in python 
Python :: pip install 
Python :: python pickle dataframe 
Python :: calculating auc 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =