In [1]:
%matplotlib inline
In [122]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
In [3]:
a = np.random.random(10)
In [4]:
def make_viz(arr):
def showit(width, height, cast_as, global_bounds = False):
v = arr.view(cast_as)[:width*height].reshape((width, height))
plt.clf()
if global_bounds == True:
mi = np.iinfo(cast_as).min
ma = np.iinfo(cast_as).max
elif global_bounds in ("u1", "u2", "u4", "u8"):
print("Using ...")
mi = np.iinfo(global_bounds).min
ma = np.iinfo(global_bounds).max
print("Using ...", mi, ma, v.min(), v.max())
else:
mi = v.min()
ma = v.max()
print(mi, ma)
plt.imshow(v, vmin = mi, vmax = ma, cmap="viridis")
return showit
In [5]:
arr = np.arange(256).reshape((16, 16), order="F").astype("uint8")
In [6]:
s = make_viz(arr)
In [7]:
s(16, 16, "uint8")
In [8]:
arr, _ = np.mgrid[0:1:256j, 0:1:256j]
In [9]:
s = make_viz(arr)
In [10]:
arr.size, arr.view("uint64").size
Out[10]:
In [11]:
256*256*2
Out[11]:
In [12]:
s(1024, 1024, "uint8", "u1")
In [13]:
np.iinfo("u1")
Out[13]:
In [14]:
131072/256
Out[14]:
In [15]:
arr
Out[15]:
In [16]:
val = "390"
arr = np.array(val, dtype="c")
In [17]:
arr.view("uint8")
Out[17]:
In [18]:
np.unpackbits(arr[0].view("uint8"))
Out[18]:
In [19]:
np.unpackbits(arr[1].view("uint8"))
Out[19]:
In [20]:
np.unpackbits(arr[2].view("uint8"))
Out[20]:
In [21]:
arr = np.array([390], dtype="f8")
In [22]:
arr
Out[22]:
In [23]:
np.unpackbits(arr.view("u1"))
Out[23]:
In [24]:
np.array("1.83970e-003", dtype="c").view("uint8")
Out[24]:
In [25]:
_.size
Out[25]:
In [29]:
a = np.array([390], dtype="f8")
a.view("u1")
Out[29]:
In [32]:
np.array([1.83970e-003], dtype="f8").view("uint8")
Out[32]:
In [33]:
!head data-readonly/IL_Building_Inventory.csv
In [115]:
import pandas as pd
df = pd.read_csv("data-readonly/IL_Building_Inventory.csv", nrows=100000)
In [116]:
df.columns
Out[116]:
In [117]:
df.shape
Out[117]:
In [118]:
df2 = df[ (df["Agency Name"] == "University of Illinois") &(df["Address"] == "501 E Daniel")]
In [119]:
print(df2.to_json(lines=True, orient="records"))
In [120]:
[_ for _ in list(df.Address) if "Daniel" in str(_)]
Out[120]:
In [121]:
df.shape
Out[121]:
In [130]:
plt.style.use("ggplot")
plt.rcParams["xtick.labelsize"] = 20
plt.rcParams["ytick.labelsize"] = 20
In [ ]:
x = np.mgrid[0:2*np.pi:64j]
In [161]:
fig = plt.figure(figsize=(15, 12))
plt.plot(x, np.sin(x), '.-')
plt.ylim(-1.1, 1.1)
plt.xlim(-0.1, 2.0*np.pi + 0.1)
Out[161]:
In [162]:
fig = plt.figure(figsize=(15, 12))
for i, n in enumerate([1, 2, 8, 16]):
ax = fig.add_subplot(2, 2, i + 1)
ax.plot(x[::n], np.sin(x[::n]), '.-')
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(-0.1, 2.0*np.pi + 0.1)
ax.set_title("Step size %s" % n)
In [165]:
fig = plt.figure(figsize=(15, 12))
for i, n in enumerate([1, 2, 8, 16]):
ind = np.arange(x.size)
np.random.shuffle(ind)
ind = ind[:x.size//n]
ind.sort()
ax = fig.add_subplot(2, 2, i + 1)
ax.plot(x[ind], np.sin(x[ind]), '.-')
ax.set_title("Random %s" % (x.size/n))
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(-0.1, 2.0*np.pi + 0.1)
In [170]:
x = np.mgrid[0:2*np.pi:64j]
In [171]:
fig = plt.figure(figsize=(15, 12))
plt.plot(x, np.sin(3*x), '.-')
plt.ylim(-1.1, 1.1)
plt.xlim(-0.1, 2.0*np.pi + 0.1)
Out[171]:
In [172]:
fig = plt.figure(figsize=(15, 12))
for i, n in enumerate([1, 2, 8, 16]):
ax = fig.add_subplot(2, 2, i + 1)
ax.plot(x[::n], np.sin(3*x[::n]), '.-')
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(-0.1, 2.0*np.pi + 0.1)
ax.set_title("Step size %s" % n)
In [173]:
fig = plt.figure(figsize=(15, 12))
for i, n in enumerate([1, 2, 8, 16]):
ind = np.arange(x.size)
np.random.shuffle(ind)
ind = ind[:x.size//n]
ind.sort()
ax = fig.add_subplot(2, 2, i + 1)
ax.plot(x[ind], np.sin(3*x[ind]), '.-')
ax.set_title("Random %s" % (x.size/n))
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(-0.1, 2.0*np.pi + 0.1)
In [174]:
a = []
while len(a) < 5:
a.append(input("Hello!"))
In [ ]: