This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import timeit | |
def random_data(N): | |
# Generate some random data. | |
return np.random.uniform(0., 10., N) | |
# Data lists. | |
array1 = np.array([random_data(4) for _ in range(1000)]) | |
array2 = np.array([random_data(3) for _ in range(2000)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import timeit | |
def random_data(N): | |
# Generate some random data. | |
return np.random.uniform(0., 10., N) | |
# Data lists. | |
array1 = np.array([random_data(4) for _ in range(10000)]) # pump up the number of iterations in optfunc | |
array2 = np.array([random_data(3) for _ in range(100)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import matplotlib.pyplot as plt | |
G = nx.Graph() | |
G.add_edges_from( | |
[(7, 11), (7, 8), (5, 11), (3, 8), (3, 10), (11, 2), (11, 9), | |
(11, 10), (8, 9)]) | |
pos = nx.spring_layout(G, iterations=100) | |
for node, loc in pos.iteritems(): | |
print('{n}: {l}'.format(n=node, l=loc)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def memo(f): | |
"""Decorator that caches the return value for each call to f(args). | |
Then when called again with same args, we can just look it up.""" | |
cache = {} | |
def _f(*args): | |
try: | |
return cache[args] | |
except KeyError: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import calendar | |
import pytz | |
import datetime as DT | |
tz1 = pytz.timezone('US/Eastern') | |
utc = pytz.timezone('UTC') | |
now = utc.localize(DT.datetime(2002, 10, 27, 7, 0, 0)) | |
now_tz = now.astimezone(tz1) | |
now_epoch = calendar.timegm(now_tz.utctimetuple()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import calendar | |
import time | |
import pytz | |
import datetime as DT | |
utc = pytz.timezone('UTC') | |
for tzname in [name for name in pytz.all_timezones if 'Brazil' in name]: | |
tz1 = pytz.timezone(tzname) | |
date = utc.localize(DT.datetime(2013, 1, 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
import timeit | |
def naive_power(m, n): | |
m = np.asarray(m) | |
res = m.copy() | |
for i in xrange(1,n): | |
res *= m | |
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import warnings | |
import operator | |
import itertools as IT | |
import numpy as np | |
from numpy import nan | |
import pandas as pd | |
pd.options.display.width = 1000 | |
pd.options.display.max_rows = 1000 | |
def comparisons(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
import timeit | |
def array_equivalent(a1, a2): | |
try: | |
a1, a2 = np.asarray(a1), np.asarray(a2) | |
except (TypeError, ValueError): | |
return False | |
a1_mask = pd.isnull(a1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
nan = np.nan | |
def array_equivalent(a1, a2): | |
try: | |
a1, a2 = np.asarray(a1), np.asarray(a2) | |
except (TypeError, ValueError): | |
return False | |
a1_mask = pd.isnull(a1) |
OlderNewer