Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
fibs=(1 1)
while ((fibs[-1] < 200))
do
echo ${fibs[@]}
fibn=$((fibs[-1] + fibs[-2]))
fibs+=($fibn)
done
@tavin
tavin / consecutive.py
Created June 1, 2018 12:25
count the longest line of consecutive True along an axis
def consecutive(cond, axis):
cond = np.moveaxis(cond, axis, -1)
measure = np.zeros(cond.shape[:-1], dtype=np.uint32)
diff = np.diff(cond)
for index in np.ndindex(measure.shape):
boundary = np.flatnonzero(diff[index])
if not len(boundary):
continue
if cond[index][0]:
boundary = np.insert(boundary, 0, -1)
@tavin
tavin / quantreg-bs.py
Created May 17, 2018 17:13
b-spline quantile regression with statsmodels
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
import statsmodels.formula.api as smf
x = np.linspace(0, 2, 100)
y = np.sqrt(x) * np.sin(2 * np.pi * x) + np.random.random_sample(100)