Skip to content

Instantly share code, notes, and snippets.

View AlexEngelhardt's full-sized avatar

Alexander Engelhardt AlexEngelhardt

View GitHub Profile
@AlexEngelhardt
AlexEngelhardt / rle.py
Created February 6, 2019 12:49
Run Length Encoding in Python
"""Run-Length Encoding."""
import numpy as np
import pandas as pd
from itertools import chain
def rle_encode(ndarr):
"""
Input: ndarray
@AlexEngelhardt
AlexEngelhardt / cv.folds
Created April 15, 2015 12:02
Function to generate list of test set indices for cross validation
cv.folds <- function(n, folds = 10) { split(sample(1:n), rep(1:folds, length = n)) }
## cv_indices <- cv.folds(length(testable_rows), K) # list of 10 indices of testable_rows
## cv_groups <- lapply(cv_indices, function(x) testable_rows[x])
@AlexEngelhardt
AlexEngelhardt / multiplot.R
Created March 3, 2015 08:36
Function to arrange multiple ggplots
# From: http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_%28ggplot2%29/
# Multiple plot function
#
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
# - cols: Number of columns in layout
# - layout: A matrix specifying the layout. If present, 'cols' is ignored.
#
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),
# then plot 1 will go in the upper left, 2 will go in the upper right, and