Skip to content

Instantly share code, notes, and snippets.

function newCurve = spline3d(curve, dt)
% interpote a 3d curve using spline
% path 3*x
% newPath 3*x
x = curve(1, :);
y = curve(2, :);
z = curve(3, :);
t = cumsum([0;sqrt(diff(x(:)).^2 + diff(y(:)).^2 + diff(z(:)).^2)]);
sx = spline(t,x);
sy = spline(t,y);
function gplot3(A, xyz)
% GPLOT3(A, xyz) is nearly the same as GPLOT(A, xy) except
% that the xyz variable requires a third dimension.
% This function takes an adjacency matrix and visualizes it
% in 3D.
[d e] = size(A);
if d ~= e
error('A matrix must be square.');
end
function quickPlot(varargin)
% Quickly plot point clouds of data.
% This works for up to 5 datasets of
% 1D or 2D or 3D data, regardless of the
% row-order or column-order format.
%
% Also works with 2D or 3D matrices.
%
% How to use this function:
% --> Give it data. That's pretty much it.
import urllib
import sys
import re
troll = "dQw4w9WgXcQ"
urlsource = sys.argv[1]
f = urllib.urlopen(urlsource)
s = f.readlines()
In [1]: import numpy as np
In [2]: from scipy.spatial.distance import cdist
In [3]: from distlib import pairwise_cython_blas, pairwise_cython
In [4]: a = np.random.random(size=(1000,3))
In [5]: %timeit cdist(a,a)
100 loops, best of 3: 11.3 ms per loop
import numpy as np
from collections import deque
import time
import threading
import matplotlib.pyplot as plt
def rollingFFT(s, n, dt):
fy = np.fft.fft(s)
# Frequencies associated with each samples
@asw456
asw456 / convert.py
Created July 19, 2013 04:18 — forked from paulgb/convert.py
'''
Convert Yelp Academic Dataset from JSON to CSV
Requires Pandas (https://pypi.python.org/pypi/pandas)
By Paul Butler, No Rights Reserved
'''
import json
import pandas as pd
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD 150,000 ns 0.15 ms
Read 1 MB sequentially from memory 250,000 ns 0.25 ms
Round trip within same datacenter 500,000 ns 0.5 ms
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import sys
class Polyomino(object):
def __init__(self, iterable):
self.squares = tuple(sorted(iterable))
def __repr__(self):
from numpy import *
from scipy.stats import beta
class BetaBandit(object):
def __init__(self, num_options=2, prior=(1.0,1.0)):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
self.prior = prior