Skip to content

Instantly share code, notes, and snippets.

@kpykc
kpykc / einsum.py
Created October 5, 2016 11:40 — forked from mblondel/einsum.py
Einstein sum notation
import numpy as np
rng = np.random.RandomState(0)
print "Trace"
A = rng.rand(3, 3)
print np.trace(A)
print np.einsum("ii", A)
print
@kpykc
kpykc / stride_tricks.py
Created October 5, 2016 11:40 — forked from seberg/stride_tricks.py
numy stride tricks based functions for changing the shape and axis order of arrays.
import numpy as np
from collections import defaultdict as _dd
def rolling_window(array, window=(0,), asteps=None, wsteps=None, axes=None, toend=True):
"""Create a view of `array` which for every point gives the n-dimensional
neighbourhood of size window. New dimensions are added at the end of
`array` or after the corresponding original dimension.
Parameters
----------
@kpykc
kpykc / learn.lua
Created October 5, 2016 11:16 — forked from tylerneylon/learn.lua
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@kpykc
kpykc / Retina Figures.ipynb
Created June 2, 2016 21:33 — forked from minrk/Retina Figures.ipynb
2x plots for Retina displays with matplotlib and the IPython Notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kpykc
kpykc / magic_memit.py
Created February 24, 2016 17:22 — forked from vene/magic_memit.py
memit: magic memory usage benching for IPython
# Author: Vlad Niculae <vlad@vene.ro>
# Makes use of memory_profiler from Fabian Pedregosa
# available at https://github.com/fabianp/memory_profiler
from IPython.core.magic import Magics, line_magic, magics_class
class MemMagics(Magics):
@line_magic
def memit(self, line='', setup='pass'):
#coding: utf-8
import keyring
from cStringIO import StringIO
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
from email import Charset
from email.generator import Generator
import smtplib
@kpykc
kpykc / declarations_api.py
Created December 21, 2015 03:49 — forked from dchaplinsky/declarations_api.py
Simple example of how to export all assets declarations from declarations.com.ua website.
import requests
import json
from time import sleep
data = []
print("Fetching page #%s" % 1)
r = requests.get("http://declarations.com.ua/search?format=json").json()
data += r["results"]["object_list"]
@kpykc
kpykc / gst-appsrc.c
Created December 13, 2015 02:00 — forked from floe/gst-appsrc.c
example appsrc for gstreamer 1.0 with own mainloop & external buffers
// example appsrc for gstreamer 1.0 with own mainloop & external buffers. based on example from gstreamer docs.
// public domain, 2015 by Florian Echtler <floe@butterbrot.org>. compile with:
// gcc --std=c99 -Wall $(pkg-config --cflags gstreamer-1.0) -o gst gst.c $(pkg-config --libs gstreamer-1.0) -lgstapp-1.0
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <stdint.h>
int want = 1;
import zmq
import time
from multiprocessing import Process
import numpy as np
from pprint import pprint
import json
np.set_printoptions(precision=3)
import zmq
import time
from multiprocessing import Process
import numpy as np
np.set_printoptions(precision=3)
def send_array(socket, A, flags=0, copy=True, track=False):
"""send a numpy array with metadata"""
md = dict(dtype=str(A.dtype), shape=A.shape)