Skip to content

Instantly share code, notes, and snippets.

Travis E. Oliphant teoliphant

Block or report user

Report or block teoliphant

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@teoliphant
teoliphant / simple_interpolation.py
Last active Aug 30, 2018
Vectorized linear interpolation
View simple_interpolation.py
# The kernel function is
# roughtly equivalent to new[:] = np.interp(xnew, xvals, yvals)
# But this is broadcast so that it can be run many, many times
# quickly.
# Call using ynew = interp1d(xnew, xdata, ydata)
# ynew.shape will be xnew.shape
# Also, ydata.shape[-1] must be xdata.shape[-1]
# and if ydata or xdata have ndim greater than 1, the initial dimensions
# must be xnew.shape:
@teoliphant
teoliphant / Best median-fit line
Last active Oct 13, 2016
Find a good linear relationship between data using the 3 Median Method.
View Best median-fit line
My 11 year-old son is learning about regression in his 9th grade math class.
For them regression is two tables of data and a calculator button.
The graphing calculators also provide a button to find the best "median-fit" line and
the students were asked to find it as well as the regression line. The regression line can
easily be found with numpy.polyfit(x, y, 1).
I did not know of a function to calculate the best "median-fit" line. I had to review a few
online videos to learn exactly what a best "median-fit" line is and found the 3-median method
for determining the best "median-fit" line. It's sometimes called the median median fit.
@teoliphant
teoliphant / rolling.py
Last active Dec 5, 2018
Create a function to make a "sliding_window" output array from an input array and a rolling_window size.
View rolling.py
import numpy as np
def array_for_sliding_window(x, wshape):
"""Build a sliding-window representation of x.
The last dimension(s) of the output array contain the data of
the specific window. The number of dimensions in the output is
twice that of the input.
Parameters
@teoliphant
teoliphant / circ_mask.png
Last active Dec 29, 2015
Create masks (circle and ellipse) starting with a simple level cutoff.
@teoliphant
teoliphant / using_numba.ipynb
Created Mar 10, 2013
Using Numba to implement a summation
View using_numba.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@teoliphant
teoliphant / life.py
Created Aug 14, 2012
Array-oriented version of the game of life
View life.py
from numpy.random import rand
from numpy import r_, ix_, uint8, roll
import matplotlib.pyplot as plt
import time
size = 200
GRID = (rand(size,size) > 0.75).astype(uint8)
# Rotate indices because the world is round
indx = r_[0:size]
up = roll(indx, -1)
You can’t perform that action at this time.