2
我正在尝试为图像创建亲和矩阵。我现在试图使用简单的像素值差异,我的图像是84x84,展平它是一个大小为7056的矢量,它给出了大小为7056x7056的相关矩阵A.为了填补在亲和度矩阵的值,我开始带有明显的方法:使用Numpy的亲和矩阵计算
import matplotlib.pyplot as plt
import numpy as np
Img = plt.imread("twoObj.bmp")
Img2 = Img.flatten()
(n,) = Img2.shape
print n
A = np.zeros((n,n))
for i in range(n):
for j in range(n):
A[i,j] = np.abs(Img2[i] - Img2[j])
但时间太长执行。 Numpy中是否有内置的方法,或者可用库来更快地运行?
我不得不使用np.subtract.outer(Img2,Img2),但它工作!谢谢。 – user423805
@ user423805 - 是的!这是我的一个错字。很高兴你看到它! –