Pillow 是基于PIL
pip install Pillow
colorbar
Set Colorbar Range in matplotlib
设置统一colorbar范围:im = ax.imshow(data, vmin=a, vmax=b)
Kernel died, restarting
终端 python 文件名
报错 Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so.
Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so
conda install nomkl numpy scipy scikit-learn numexpr
conda remove mkl mkl-service
【TensorFlow】学习率、迭代次数和初始化方式对准确率的影响
画图
python:散点图对数刻度
Python matplotlib.cm.jet Examples
【数字的可视化:python画图之散点图sactter函数详解】
使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
list 去重,保持顺序
ids = [1,4,3,3,4,2,3,4,5,6,1]
ne = list(set(ids))
print ids.index
ne.sort(key = ids.index)
print ne
去除重复,去除矛盾点(即部分重复)
#remove duplicate and remove conflict
tuples = [(1, 1, 0.0), (2, 2, 0.0), (2, 1, 0.0), (1, 1, 1.0), (1, 1, 0.0),(2, 1, 0.0)]
print tuples
tuples = list(set(tuples)) #remove duplicate
print tuples
tuples_infos = [tuples_info[0:2] for tuples_info in tuples]
print tuples_infos
tuples_non = [tuples[idx] for idx in range(len(tuples_infos)) if tuples_infos.count(tuples_infos[idx]) == 1]
print tuples_non #remove conflict
print ''
#remain duplicate. but remove conflict
tuples = [(1, 1, 0.0), (2, 2, 0.0), (2, 1, 0.0), (1, 1, 1.0), (1, 1, 0.0),(2, 1, 0.0)]
print tuples
tuples_nodup = list(set(tuples))
print tuples_nodup
tuples_infos = [tuples_info[0:2] for tuples_info in tuples_nodup]
print tuples_infos
tuples_non = [tuples[idx] for idx in range(len(tuples)) if tuples_infos.count(tuples[idx][0:2]) == 1]
print tuples_non
计算运行时间
import time
start=time.clock()
end=time.clock()
print('Runing time.%s Seconds'%(end-start))
Python NumPy计算欧氏距离(Euclidean Distance)
速度较快
# 样本数据
coords1 = [1, 2, 3]
coords2 = [4, 5, 6]
np_c1 = np.array(coords1)
np_c2 = np.array(coords2)
# 经典 For循环
def eucldist_forloop(coords1, coords2):
""" Calculates the euclidean distance between 2 lists of coordinates. """
dist = 0
for (x, y) in zip(coords1, coords2):
dist += (x - y)**2
return dist**0.5
# 生成器表达式
def eucldist_generator(coords1, coords2):
""" Calculates the euclidean distance between 2 lists of coordinates. """
return sum((x - y)**2 for x, y in zip(coords1, coords2))**0.5
IOError: [Errno 2] No such file or directory
f1 = open('%s/query_%s.txt'%(folder_queries,epoch_idx))
修改为
f1 = open('%s/query_%s.txt'%(folder_queries,epoch_idx),'w')