Python
python
[... for ...] array comp / (... for ...) generator comp / {... for ...} dict/set comp
dict.setdefault(key, default) # dict[key] ??= default
vals # Object.entries
breakpoint()
pdbpp
f"{x=}"
reveal_type()
IPython
%timeit
%pprof
numpy
rfn.unstructured_to_structured / structured_to_unstructured
np.zeros, npzeros_like, np.full, np.full_like
np.all(a == b) # element-wise comparison + all w/ axis = row/col-wise comparision
np.argsort + indexer
np.savetxt
fmt="%.5f とか
連結
np.concatenate [a, ...] + [b, ...] = [a, ..., b, ...]
np.stack a + b + c = [a,b,c]
vstack/hstack/dstack ... v/h/dの軸で連結
1-d array の時だけ (h) 、2-d 以上なら (v, h, d, ...)
その軸があってもなくても動くので、stackとconcatの間の子みたいな感じがある
np.column_stack [a, ...] + [b, ...] = [[a, b], ...]
hstackは (h) をh軸で連結するのに対し、column_stackは (v) をh軸で連結する、みたいな解釈ができる
2-d 以上のarrayを混ぜるとそのままh軸で連結
np.block 内側から axis=-1, axis=-2, ... で連結していく
ABCDが(2,2)とかで np.block([[A,B],[C,D]]) とかすると、axis=-1 と axis=-2 で順に連結されて (4,4) になる
分割
split(n) n要素ずつに分割
split(i) = [0:i[0]], [i[0]:i[1]], ..., [i[n]:]
einsum(まだわからん)
itertools
islice # slice for iterator
zip_longest
tee
matplotlib
import matplotlib.pyplot as plt
plt.figure(figsize=(w,h))
fig.add_subplot
plt.imshow(np_2darr)
plt.plot (ys) (xs, ys)
plt.hist # histgram
plt.scatter(xs, ys)
s = size, c = color
plt.xlimit/ylimit
plt.axhline / axvline # 水平線・垂直線
plt.subplot / plt.subplots
plt.text # text (+ box)
plt.annotate # arrow + text
Shapely
pandas
groupby
df.groupby(df["hoge"].cumsum()) # 連続してるものでわける方のgroupby
quantile # percentile
describe