【发布时间】:2020-05-05 20:07:02
【问题描述】:
我想找到一种更快的方法来计算矩阵v。请注意,如果高度 = 宽度,则矩阵 v 是对称的,v = v.T。宽度和高度是任意正整数。
v = np.zeros((height, width)) # rows columns
# region center
cr = np.round(height / 2)
cc = np.round(width / 2)
# there has to be a quicker way to do this
for w in range(width):
v[:, w] = [np.sqrt((w - cc) ** 2 + (h - cr) ** 2) for h in range(height)]
【问题讨论】:
-
我不知道如何称呼这个操作,但它似乎与矩阵的 L2 范数无关,这是最大的特征值量级。也许标题应该调整一下?
标签: python performance numpy matrix