Skip to content

Instantly share code, notes, and snippets.

View chelseatroy's full-sized avatar

Chelsea Troy chelseatroy

View GitHub Profile
@chelseatroy
chelseatroy / main.py
Created November 8, 2018 04:43
Calling Cython Multiplication
print("Timing cython multiplication:\n")
start = time.time()
python_result = multiplication.cython_multiplication(a, b, c, 2000, 2000)
end = time.time()
print(end - start)
@chelseatroy
chelseatroy / Chapter_19.c
Created November 9, 2018 21:06
Definition of the Numpy Iterator Struct from Beautiful Code
typedef struct {<-------------------------immutable key value data store to iterate over given array
PyObject_HEAD
int nd_m1;<------------------------number of dimensions in array minus 1
npy_intp index;<-------------------counter for element that iterator is at
npy_intp size;<--------------------number of elements in array
npy_intp coords[NPY_MAXDIMS];<-----the N-dimensional location of the current element
npy_intp dims_m1[NPY_MAXDIMS];<----number of elements along each dimension minus 1
npy_intp strides[NPY_MAXDIMS];<----number of bytes separating the elements in each dimension
npy_intp backstrides[NPY_MAXDIMS];<number of bytes to subtract to return to beginning of dimension
npy_intp factors[NPY_MAXDIMS];<----for converting from 1D index to N-dimensional coords in 1D arrays
@chelseatroy
chelseatroy / iterators.c
Created November 9, 2018 22:46
Numpy MultiIterator
/*NUMPY_API
* Get MultiIterator from array of Python objects and any additional
*
* PyObject **mps -- array of PyObjects
* int n - number of PyObjects in the array
* int nadd - number of additional arrays to include in the iterator.
*
* Returns a multi-iterator object.
*/
NPY_NO_EXPORT PyObject *
@chelseatroy
chelseatroy / features.py
Created January 11, 2019 05:02
Example total_density
def total_density(image):
return image.sum(axis=1).sum()
@chelseatroy
chelseatroy / features.py
Created January 11, 2019 05:04
Examples for Symmetry
def horizontal_asymmetry(image):
left, right = np.hsplit(image, 2)
right_flipped = np.flip(right, axis=1)
return np.sum(left - right_flipped) ** 2
def vertical_asymmetry(image):
top, bottom = np.vsplit(image, 2)
bottom_flipped = np.flip(bottom, axis=0)
return np.sum(top - bottom_flipped) ** 2
@chelseatroy
chelseatroy / prepare_data.ipynb
Created March 13, 2019 17:50
Example Physician and Procedure Data Preparation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chelseatroy
chelseatroy / exploratory_analysis.ipynb
Last active March 13, 2019 18:29
Exploratory Analysis
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chelseatroy
chelseatroy / specialty_data.py
Last active April 1, 2019 00:43
Example with Dask
import numpy as np
import pandas as pd
from dask import dataframe as dd
from dask.multiprocessing import get
from multiprocessing import cpu_count
num_cores = cpu_count()
from datetime import date
def extract_procedure_features(physician_procedures):
one_hot_procedures = pd.get_dummies(physician_procedures.procedure_code, prefix='procedure')
@chelseatroy
chelseatroy / specialty_data.py
Last active March 26, 2019 18:59
Example with Apply
import numpy as np
import pandas as pd
from datetime import date
def extract_procedure_features(physician_procedures):
one_hot_procedures = pd.get_dummies(physician_procedures.procedure_code, prefix='procedure')
dummied_procedures = pd.concat([physician_procedures.number_of_patients, one_hot_procedures], axis=1)
def numerize(row):
return np.asarray(row.number_of_patients) * np.asarray(row)
@chelseatroy
chelseatroy / commands.sh
Created April 4, 2019 19:46
Devise Setup Example
echo "gem 'devise'" >> Gemfile # Or edit Gemfile and add line: gem 'devise'
bundle install # Fetch and install the gems
rails generate devise:install # Creates config file, etc.
rails generate devise user # Create model class, routes, etc.
rake db:migrate # Create user table
rails generate devise:views users # Creates (minimal) views
# Code sample courtesy of launch school: https://launchschool.com/blog/how-to-use-devise-in-rails-for-authentication