Skip to content

Instantly share code, notes, and snippets.

View zhezh's full-sized avatar

Zhe Zhang zhezh

  • Microsoft Research Asia (Research Intern)
View GitHub Profile
@zhezh
zhezh / colormap.py
Last active May 10, 2020 01:20
[plt colormap] #plot #python
# https://matplotlib.org/3.1.1/gallery/color/colormap_reference.html
import numpy as np
import matplotlib.pyplot as plt
cm = plt.get_cmap('Reds')
print(cm.N) # how many color levels in this cm
# cm takes list or single value in [0,N-1] or [0.0, 1.0], depending on the value type
# value lower or bigger than boundary are default to boundry color
@zhezh
zhezh / numpy_div0.py
Last active April 8, 2020 23:39
[numpy除零自动纠正] numpy np div 0 #numpy
# 自动处理除零错误
# numpy >= 1.7
a = np.array([-1, 0, 1, 2, 3], dtype=float)
b = np.array([ 0, 0, 0, 2, 2], dtype=float)
# If you don't pass `out` the indices where (b == 0) will be uninitialized!
c = np.divide(a, b, out=np.zeros_like(a), where=b!=0)
print(c)
# [ 0. 0. 0. 1. 1.5]
@zhezh
zhezh / per-layer-lr.ipynb
Last active April 8, 2020 23:07
[pytorch 分层设置学习率] #pytorch
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.