Skip to content

Instantly share code, notes, and snippets.

import numpy as np
def normalize(arr):
# normalize a 1d to [0,1] using
# empirical cdf
idx = np.argsort(arr)
cdf = 1 - (idx / arr.size)
return cdf[idx]
import scipy.special
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-10, 10, 200)
y = 4*(x**3) - 2*(x**2) + x
y += np.random.normal(size=y.shape[0])*500
plt.plot(x, y, 'ro')
plt.show()
@TimSchmeier
TimSchmeier / app.py
Last active September 3, 2015 20:51 — forked from rduplain/app.py
Plot a PNG using matplotlib in a web request, using Flask.
"Plot a PNG using matplotlib in a web request, using Flask."
# Install dependencies, preferably in a virtualenv:
#
# pip install flask matplotlib
#
# Run the development server:
#
# python app.py
#
@TimSchmeier
TimSchmeier / min-char-rnn.py
Last active August 29, 2015 14:27 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
# Mostly taken from: http://nbviewer.ipython.org/github/bmcfee/librosa/blob/master/examples/LibROSA%20demo.ipynb
import librosa
import matplotlib.pyplot as plt
# Load sound file
y, sr = librosa.load("filename.mp3")
# Let's make and display a mel-scaled power (energy-squared) spectrogram
S = librosa.feature.melspectrogram(y, sr=sr, n_mels=128)
import numpy as np
def freq2mel(freq):
return 1127.01048 * np.log(1 + freq / 700.0)
def mel2freq(mel):
return (np.exp(mel / 1127.01048) - 1) * 700
def mel_binning_matrix(specgram_window_size, sample_frequency, num_mel_bands):