上传文件至 /
This commit is contained in:
10
yzz.py
Normal file
10
yzz.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
image = np.array([
|
||||||
|
[100, 150, 200],
|
||||||
|
[80, 120, 180],
|
||||||
|
[60, 90, 140]
|
||||||
|
], dtype=np.uint8)
|
||||||
|
|
||||||
|
print("原图:")
|
||||||
|
print(image)
|
||||||
23
yzz2.py
Normal file
23
yzz2.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
# 假设这是从图像中提取的2个特征图
|
||||||
|
feature_map1 = np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]])
|
||||||
|
feature_map2 = np.array([[1, 1, 1], [1, 0, 0], [1, 0, 0]])
|
||||||
|
|
||||||
|
# 补全代码:将特征图展平为向量
|
||||||
|
vector1 = feature_map1.flatten() # 展平
|
||||||
|
vector2 = feature_map2.flatten() # 展平
|
||||||
|
|
||||||
|
print("vector1:", vector1)
|
||||||
|
print("vector2:", vector2)
|
||||||
|
|
||||||
|
# 1. 计算欧几里得距离
|
||||||
|
euclidean_dist = np.linalg.norm(vector1 - vector2)
|
||||||
|
|
||||||
|
# 2. 计算余弦相似度
|
||||||
|
cos_sim = np.dot(vector1, vector2) / (np.linalg.norm(vector1) * np.linalg.norm(vector2))
|
||||||
|
|
||||||
|
# 输出结果
|
||||||
|
print("\n===== 计算结果 =====")
|
||||||
|
print("欧几里得距离:", euclidean_dist)
|
||||||
|
print("余弦相似度:", cos_sim)
|
||||||
Reference in New Issue
Block a user