Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env julia
# Demonstrate the following features:
# 1) Complex type compatible with h5py and pytables Python modules.
# 2) Create dataset with this type, chunking, etc.
# 3) Write data in pieces, not all at once.
# 4) Read back data in h5py format as native julia complex type.
#
# Brian Hawkins
# 2018-09-08
# MIT license
#!python
# Adapted from StackOverflow user mab
# http://stackoverflow.com/a/33672015/112699
import timeit
import numpy as np
import pandas as pd
from IPython.display import display
def profile_this(methods, setup='', n=100, niter=10**4):
print('n: {0}, niter: {1:.0e}'.format(n, niter))
@bhawkins
bhawkins / graffiti.py
Created March 15, 2013 03:49
A python script to plot the mysterious equation found in some Israeli graffiti.
#!/usr/bin/env python
import numpy as np
import pylab as p
from mpl_toolkits.mplot3d import Axes3D
n = 201
R = 1.0
gamma = 1
@bhawkins
bhawkins / time-numpy-deep-copy.py
Last active December 15, 2016 20:52
Check the performance of various ways of copying a numpy array.
#!/usr/bin/env python
from __future__ import print_function
import timeit
import numpy as np
from distutils.version import StrictVersion
from six.moves import range
setup = """
import numpy as np
from six.moves import range
@bhawkins
bhawkins / fftsize.py
Last active March 8, 2020 19:21
Python code for computing fast FFT sizes.
#!/usr/bin/env python
from __future__ import print_function
import numpy as np
from numpy import log, ceil
def nextpower(n, base=2.0):
"""Return the next integral power of two greater than the given number.
Specifically, return m such that
m >= n
@bhawkins
bhawkins / medfilt.py
Created August 30, 2012 17:47
1D median filter using numpy
#!/usr/bin/env python
import numpy as np
def medfilt (x, k):
"""Apply a length-k median filter to a 1D array x.
Boundaries are extended by repeating endpoints.
"""
assert k % 2 == 1, "Median filter length must be odd."