This file contains 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
from sklearn.datasets import load_iris | |
from scipy.sparse import csr_matrix, csc_matrix | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.ensemble import BaggingClassifier | |
iris = load_iris() | |
data = iris['data'] | |
labels = iris['target'] | |
csc = csc_matrix(data) |
This file contains 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 concurrent.futures | |
import multiprocessing | |
import random | |
from fast import FastProcessPoolExecutor | |
import time | |
from functools import partial | |
def fn2(fn, chunk): | |
return [fn(*args) for args in zip(*chunk)] | |
class FastProcessPoolExecutor(concurrent.futures.ProcessPoolExecutor): |
This file contains 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 concurrent.futures | |
import random | |
def f(x): | |
return x**2 | |
def integrate(func, start, end, num_samples=1000): | |
"""uses random sampling to integrate func from 'start' to 'end'""" | |
with concurrent.futures.ProcessPoolExecutor() as executor: |
This file contains 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
from math import sqrt | |
import random,time | |
import profile | |
def bellman_ford(edges): | |
numRows = len(edges) | |
numCols = len(edges[0]) | |
OPT = dict(( (len(edges)-1,x),edges[-1][x]) for x in xrange(len(edges[-1]))) | |
opt = dict(( (len(edges)-1,x),None) for x in xrange(len(edges[-1]))) |
This file contains 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 sys,time,random | |
from multiprocessing import Pool | |
def integral_helper((f,start,end,num_samples)): | |
return sum( (f((end-start)*random.random()+start) for i in xrange(num_samples))) | |
def integral(f,start,end,num_processes): | |
WORK_ITEMS = 100; | |
pool = Pool(processes=num_processes) | |
args = (f,start,end,WORK_ITEMS/num_processes) |
This file contains 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
def landon(array,k,threshold): | |
sections=[] | |
start,end=0,0 | |
for i in range(0,len(array)): | |
#print i,array[i],"start: ",start,"end: ",end | |
if array[i]<threshold: | |
start= start if arr[start]<threshold else i | |
end=i | |
else: |
This file contains 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
from time import time | |
from math import sqrt | |
def disproves(n): | |
i=2 | |
while i*i*2<n: | |
diff = n-i*i*2 | |
if not any(diff%j==0 for j in xrange(3,int(sqrt(diff))+1,2)) :return False | |
i+=1 | |
return True | |
n=3 |
This file contains 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 math | |
def isAbundant(n): | |
div = 1 | |
for i in range(2,int(math.sqrt(n))+1): | |
if n%i==0: | |
div += i if i==n/i else i+(n/i) | |
return True if div>n else False | |
def sumOfUniqueAbundantPairSums(): |
This file contains 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 math | |
import time | |
def isAbundant(n): | |
div = [1] | |
for i in range(2,int(math.sqrt(n))+1): | |
if n%i==0: | |
div += [i] if i==n/i else [i,n/i] | |
return True if sum(div)>n else False |
This file contains 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 math | |
import time | |
import itertools | |
def isAbundant(n): | |
div = [1] | |
for i in range(2,int(math.sqrt(n))+1): | |
if n%i==0: | |
div += [i] if i==n/i else [i,n/i] | |
return True if sum(div)>n else False |
NewerOlder