Skip to content

Instantly share code, notes, and snippets.

@richardotis
richardotis / autograd_utils.py
Created November 5, 2015 16:30
Integrating SymPy with autograd for efficient automatic differentiation of lambdify'd functions
"""
This module manages interactions with the autograd library.
"""
import autograd.numpy as anp
import numpy as np
from autograd import elementwise_grad, jacobian
from sympy import lambdify
# NumPyPrinter requires unreleased sympy 0.7.7 (in sympy master)
# if you aren't using Piecewise or logical operators
# you can change NumPyPrinter to LambdaPrinter in this module
@whophil
whophil / ipython-notebook.conf
Last active August 18, 2018 05:15
Upstart file (Ubuntu) for Jupyter / IPython notebook
start on filesystem or runlevel [2345]
stop on shutdown
description "Jupyter / IPython Notebook Upstart script"
script
export HOME="/home/phil/Notebooks"; cd $HOME
echo $$ > /var/run/ipython_start.pid
exec su -s /bin/sh -c 'exec "$0" "$@"' phil -- /home/phil/Enthought/Canopy_64bit/User/bin/jupyter-notebook --config='/home/phil/.jupyter/jupyter_notebook_config.py'
end script
# Create some sample data
CV_1 <- 0.2
CV_2 <- 0.3
Mean <- 65
sigma_1 <- sqrt(log(1 + CV_1^2))
mu_1 <- log(Mean) - sigma_1^2 / 2
sigma_2 <- sqrt(log(1 + CV_2^2))
mu_2 <- log(Mean) - sigma_2^2 / 2
q <- c(0.25, 0.5, 0.75, 0.9, 0.95)
SummaryTable <- data.frame(
@dchaplinsky
dchaplinsky / declarations_api.py
Last active December 3, 2021 00:06
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=opendata").json()
data += r["results"]["object_list"]
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)
@HHammond
HHammond / Pandas Table Summary
Last active February 3, 2018 04:51
Pandas Pretty Table CSS
import numpy as np
import pandas as pd
from functools import partial
def summary(df, fn=np.sum, axis=0, name='Total',
table_class_prefix='dataframe-summary'):
"""Append a summary row or column to DataFrame.
Input:
------
@atinfinity
atinfinity / oclMat_custom_kernel.cpp
Last active September 14, 2023 07:26
sample code to execute custom OpenCL kernel on OpenCV 2.4.9
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ocl/ocl.hpp>
// cl_mem構造体を参照するためにインクルード
#if defined __APPLE__
#include <OpenCL/cl.h>
#else
#include <CL/cl.h>
#endif
@moorepants
moorepants / example_results.txt
Last active August 12, 2022 16:54
Figuring out how to do speedy evaluation of lists of SymPy expressions.
Testing results.
Timing the functions.
Timing: cython
cython time: 0.00288254904747 s
Timing: numpy_broadcast
numpy_broadcast time: 0.00597401690483 s
@mike-lawrence
mike-lawrence / Makeconf_patch
Created March 3, 2014 17:04
Patch for R's Makeconf on Mavericks (uses clang and gfortran)
--- /Library/Frameworks/R.framework/Resources/etc/Makeconf 2013-09-25 08:59:05.000000000 -0300
+++ Makeconf 2014-03-03 13:01:00.000000000 -0400
@@ -14,11 +14,11 @@
AWK = awk
BLAS_LIBS = -L$(R_HOME)/lib$(R_ARCH) -lRblas
C_VISIBILITY =
-CC = llvm-gcc-4.2 -arch x86_64 -std=gnu99
+CC = clang -arch x86_64 -std=gnu99
CFLAGS = -mtune=core2 -g -O2 $(LTO)
CPICFLAGS = -fPIC