Skip to content

Instantly share code, notes, and snippets.

@karpathy
karpathy / min-char-rnn.py
Last active June 21, 2024 13:50
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)
@takuma7
takuma7 / opencv-fourcc-on-mac-os-x.md
Last active April 3, 2024 07:29
OpenCV Video Writer on Mac OS X
import cv2
import numpy as np
def in_front_of_both_cameras(first_points, second_points, rot, trans):
# check if the point correspondences are in front of both images
rot_inv = rot
for first, second in zip(first_points, second_points):
first_z = np.dot(rot[0, :] - second[0]*rot[2, :], trans) / np.dot(rot[0, :] - second[0]*rot[2, :], second)
first_3d_point = np.array([first[0] * first_z, second[0] * first_z, first_z])
@irachex
irachex / tarjan.py
Created October 20, 2012 08:42
Tarjan (find articulation vertex and bridges in graph) non-recursive (use stack) in Python
def tarjan(N, S, T, edges):
cnt = 0
bridges = []
visit = [0 for i in range(N)]
low = [N + 1 for i in range(N)]
ret = [False for i in range(N)]
q = [0 for i in range(N + 1)]
q[0] = (S, -1, -1)
top = 0
while top >= 0:
@endolith
endolith / frequency_estimator.py
Last active May 8, 2024 17:59
Frequency estimation methods in Python
from __future__ import division
from numpy.fft import rfft
from numpy import argmax, mean, diff, log, nonzero
from scipy.signal import blackmanharris, correlate
from time import time
import sys
try:
import soundfile as sf
except ImportError:
from scikits.audiolab import flacread