Skip to content

Instantly share code, notes, and snippets.

View WarrenWeckesser's full-sized avatar

Warren Weckesser WarrenWeckesser

View GitHub Profile
@WarrenWeckesser
WarrenWeckesser / data.py
Created January 22, 2012 17:00
Modifed version of scipy/sparse/data.py adds numpy unary ufuncs to the _data_matrix class.
"""Base class for sparse matrice with a .data attribute
subclasses must provide a _with_data() method that
creates a new matrix with the same sparsity pattern
as self but with a different data array
"""
__all__ = []
@WarrenWeckesser
WarrenWeckesser / drag_tool_demo.py
Created October 11, 2012 21:01
A script to experiment with enable's DragTool.
from enable.api import Component, ComponentEditor
from enable.tools.api import DragTool
from traits.api import HasTraits, Instance
from traitsui.api import View, UItem
class MyDragTool(DragTool):
end_drag_on_leave = True
@WarrenWeckesser
WarrenWeckesser / erlang.py
Created May 23, 2013 17:19
Alternative implementation of the erlang distribution
import numpy as np
from scipy.stats.distributions import gamma_gen
class erlang_gen(gamma_gen):
def _argcheck(self, a):
good = (a > 0) & (np.floor(a) == a)
if not np.all(good):
@WarrenWeckesser
WarrenWeckesser / erlang2.py
Last active December 18, 2015 03:08
Alternative scipy erlang class, take 2
import warnings
import numpy as np
from scipy.stats.distributions import gamma_gen, rv_continuous
class erlang_gen(gamma_gen):
"""An Erlang continuous random variable.
%(before_notes)s
@WarrenWeckesser
WarrenWeckesser / special_errors.txt
Created August 2, 2013 15:26
Test failures in scipy.special
This file has been truncated, but you can view the full file.
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................KFKFKK.K.....K...........K...KKKSF..KSSKKKKKSK..K...S..SFKKKSKKKKKKK..K........................................................
======================================================================
FAIL: test_mpmath.TestSystematic.test_chebyt_int
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/warren/anaconda/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/warren/a
@WarrenWeckesser
WarrenWeckesser / special-test-output.txt
Created August 23, 2013 23:29
Output of scipy.special tests
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................K.K..F.K.....K...........K...KKKS...KSSKKKKKSK..K...S..S.KKKSKKKKKK.............................................................
======================================================================
FAIL: test_mpmath.TestSystematic.test_ci
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/warren/anaconda/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/warren/anaconda
@WarrenWeckesser
WarrenWeckesser / create_sample24.py
Created November 14, 2013 05:05
A couple functions for generating wav files with a 3 byte sample width.
# create_sample24.py
# Author: Warren Weckesser
# License: BSD 3-Clause (http://opensource.org/licenses/BSD-3-Clause)
import numpy as np
import wave
def create_sample():
# 27 bytes (1 channel, 9 frames, 3 bytes per frame)
@WarrenWeckesser
WarrenWeckesser / wavio.py
Last active January 7, 2023 17:21
**UPDATE** I'm now maintaining this Python module in a regular github repository at https://github.com/WarrenWeckesser/wavio
# wavio.py
# Author: Warren Weckesser
# License: BSD 3-Clause (http://opensource.org/licenses/BSD-3-Clause)
import wave
import numpy as np
def _wav2array(nchannels, sampwidth, data):
"""data must be the string containing the bytes from the wav file."""
@WarrenWeckesser
WarrenWeckesser / pdtrik_check.py
Created December 16, 2013 21:57
Sample scipy.special.pdtrik on a grid.
import numpy as np
from scipy.special import pdtrik, gammaincc
import matplotlib.pyplot as plt
num_p = 41
num_lam = 21
p = np.linspace(0, 1, num_p).reshape(-1,1)
#p = np.linspace(0.99999, 1, num_p).reshape(-1,1)
lam = np.logspace(-20, 0, num_lam)
@WarrenWeckesser
WarrenWeckesser / ode_banded_jac_example.py
Last active January 3, 2016 01:48
Demonstrate a bug in the handling of a banded Jacobian when using the 'vode' solver method of scipy.integrate.ode.
import numpy as np
from scipy.integrate import ode
import matplotlib.pyplot as plt
def func(t, y, c):
return c.dot(y)
def jac(t, y, c):
return c