This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 自动处理除零错误 | |
# 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] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.