Python 读取图片文件为矩阵和保存矩阵为图片
读取图片为矩阵
import matplotlib
im = matplotlib.image.imread('0_0.jpg')
保存矩阵为图片
import numpy as np
import scipy
x = np.random.random((600,800,3))
scipy.misc.imsave('meelo.jpg', x)
比较向量的相似度 http://www.cnblogs.com/denny402/p/7028832.html
#coding:utf-8
import numpy as np
x=np.random.random(10)
y=np.random.random(10)
#方法一:根据公式求解
d1=np.dot(x,y)/(np.linalg.norm(x)*np.linalg.norm(y))
print(d1)
#方法二:根据scipy库求解
from scipy.spatial.distance import pdist
X=np.vstack([x,y])
d2=1-pdist(X,'cosine')
print(d2)
from scipy.spatial.distance import cosine, euclidean
d3 = cosine(x, y)
print(d3)
x = [1,2,3,4,5]
y = [1.1,1.8,3.2,4.1,5.2]
z = [9,9,100,15,63]
d4 = 1 - cosine(x, y)
print(d4)
d5 = 1 - cosine(x, z)
print(d5)
0.688098307243
[ 0.68809831]
0.311901692757
0.999252756811
0.790021740149