In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
In [2]:
import seaborn as sns
iris = sns.load_dataset('iris')
output = sns.pairplot(iris, hue='species');
In [3]:
from bokeh.io import output_notebook
output_notebook()
In [4]:
from bokeh.plotting import figure, show
N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = ["#%02x%02x%02x" % (r, g, 150)
for r, g in zip(np.floor(50+2*x), np.floor(30+2*y))]
TOOLS = ("resize,crosshair,pan,wheel_zoom,box_zoom,reset,tap,"
"previewsave,box_select,poly_select,lasso_select")
p = figure(tools=TOOLS)
p.scatter(x, y, radius=radii, fill_color=colors, fill_alpha=0.6, line_color=None)
show(p)
In [5]:
import numpy as np
In [6]:
def sum2d(arr):
M, N = arr.shape
result = 0.0
for i in range(M):
for j in range(N):
result += arr[i,j]
return result
In [7]:
arr = np.random.random((1000, 1000))
%timeit sum2d(arr)
In [8]:
%timeit arr.sum()
In [9]:
import numba
@numba.jit
def sum2d_fast(arr):
M, N = arr.shape
result = 0.0
for i in range(M):
for j in range(N):
result += arr[i,j]
return result
sum2d_fast(np.random.rand(2, 2))
Out[9]:
In [10]:
sum2d_fast
Out[10]:
In [11]:
%timeit sum2d_fast(arr)
In [12]:
# create an array of normally-distributed random numbers
a = np.random.randn(1000)
# multiply this array by a factor
b = a * 4
# find the minimum value
b_min = b.min()
print(b_min)
In [13]:
import dask.array as da
# create a dask array from the above array
a2 = da.from_array(a, chunks=200)
# multiply this array by a factor
b2 = a2 * 4
# find the minimum value
b2_min = b2.min()
print(b2_min)
In [14]:
#!pip install graphviz
In [15]:
from dask.dot import dot_graph
dot_graph(b2_min.dask)
Out[15]:
In [16]:
b2_min.compute()
Out[16]:
In [17]:
b.min()
Out[17]:
In [18]:
import numpy as np
data = np.random.rand(2, 3)
data
Out[18]:
In [19]:
mean = data.mean(1)
data - mean[:, None]
Out[19]:
In [20]:
import xray
xray.DataArray(data)
Out[20]:
In [21]:
xdata = xray.DataArray(data,
[('x', ['a', 'b']), ('y', [-2, 0, 2])])
xdata
Out[21]:
In [22]:
ymean = xdata.mean('y')
xdata - ymean
Out[22]:
Also... built-in integration with Dask! See http://xray.readthedocs.org/en/stable/dask.html