This file contains 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
# 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: |
This file contains 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
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. |
This file contains 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 | |
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
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) |