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 random | |
import math | |
import sys | |
def SimplePrime(n): | |
""" | |
Simple trial-division primality check. | |
Returns True if n is prime, False otherwise. |
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 as np | |
from scipy import signal | |
def conv2d_simplified(input, weight, bias=None, padding=0): | |
# This is an implemention of torch's conv2d using scipy correlate2d. Only | |
# limited options are supported for simplicity. | |
# Inspired by https://github.com/99991/NumPyConv2D/ | |
c_out, c_in_by_groups, kh, kw = weight.shape | |
if not isinstance(padding, int): | |
raise NotImplementedError() |
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 csv | |
def MergeUpdate(dataDict, update): | |
for li in update: | |
#print (li['ElectorNumber'], li['ElectorCreatedMonth'], li['ElectorChangedMonth'], li['ElectorDeletedMonth']) | |
electNum = li['ElectorNumber'].strip() | |
if int(li['ElectorCreatedMonth']) or int(li['ElectorChangedMonth']): |
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
# A script to group delivery areas into routes of roughly similar size. | |
import csv | |
from sklearn import cluster | |
from pyproj import Proj, transform | |
import numpy as np | |
from matplotlib import pyplot as plt | |
class EqualWeightClustering(object): |
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
# https://askubuntu.com/a/1337205/294281 | |
import os | |
import stat | |
import glob | |
from pathlib import Path | |
import shutil | |
if __name__=="__main__": | |
ver = "495.29.05" |
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
#pyellipse by Tim Sheerman-Chase (C) 2021 | |
#Calculate circumference of an ellipse in python (both exact and approximate approaches) | |
#This source code may be used under the CC0 license https://creativecommons.org/publicdomain/zero/1.0/ | |
# | |
#For the best exact circumference, use EllipseCircumAdlaj2012 | |
# | |
#For good approximations that are faster to compute, see EllipseCircumRamanujan2ndApprox and EllipseCircumJacobsenWaadeland1985 | |
# | |
#Incidentally, scipy has a function to exactly calculate it: | |
# C = 4.0*a*special.ellipe(e*e) |
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
#Using Keras to tackle the Inria aerial image labeling dataset | |
# https://project.inria.fr/aerialimagelabeling/ | |
import os | |
#Work around for https://github.com/tensorflow/tensorflow/issues/24496 | |
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true' | |
# Work around for https://github.com/tensorflow/tensorflow/issues/33024 | |
import tensorflow.compat as compat | |
compat.v1.disable_eager_execution() |
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 os | |
#Work around for https://github.com/tensorflow/tensorflow/issues/24496 | |
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true' | |
# Work around for https://github.com/tensorflow/tensorflow/issues/33024 | |
import tensorflow.compat as compat | |
compat.v1.disable_eager_execution() | |
import imageio | |
from sklearn.model_selection import KFold, train_test_split |
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
#Based on https://machinelearningmastery.com/how-to-develop-a-convolutional-neural-network-from-scratch-for-mnist-handwritten-digit-classification/ | |
import os | |
#Work around for https://github.com/tensorflow/tensorflow/issues/24496 | |
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true' | |
# baseline cnn model for mnist | |
from numpy import mean | |
from numpy import std | |
from matplotlib import pyplot |
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 os | |
#Work around for https://github.com/tensorflow/tensorflow/issues/24496 | |
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true' | |
# Work around for https://github.com/tensorflow/tensorflow/issues/33024 | |
import tensorflow.compat as compat | |
compat.v1.disable_eager_execution() | |
# baseline cnn model for mnist | |
import numpy as np |
NewerOlder