作业10
This commit is contained in:
39
1
Normal file
39
1
Normal file
@@ -0,0 +1,39 @@
|
||||
#第一题
|
||||
for c in "Hello":
|
||||
print(f"{c}:{ord(c)}")
|
||||
#第二题
|
||||
print(chr(65))
|
||||
assert chr(65) =='A'
|
||||
#思考题:“图像为数值化结构数据,适配计算架构;文本为语义化符号数据,需认知理解,超出当前AI本质能力。”
|
||||
#第三题
|
||||
import numpy as np
|
||||
A=np.array([3,4])
|
||||
B=np.array([1,2])
|
||||
c=A+B
|
||||
d=A*2
|
||||
print(f"A+B={c}")
|
||||
print(f"2*A={d}")
|
||||
length = np.linalg.norm(A)
|
||||
print(f"A的长度为{length}")
|
||||
#第四题
|
||||
|
||||
C = np.array([1, 2, 3])
|
||||
D = np.array([4, 5, 6])
|
||||
dot = np.dot(C, D)
|
||||
print(f"点积 = {dot}")
|
||||
import numpy as np
|
||||
|
||||
def cosine_similarity(C, D):
|
||||
norm_a = np.linalg.norm(C) # 向量a的长度
|
||||
norm_b = np.linalg.norm(D) # 向量b的长度
|
||||
return dot / (norm_a * norm_b)
|
||||
print(f"相似度 = {cosine_similarity(C, D):.3f}")
|
||||
|
||||
E=np.array([1,0])
|
||||
F=np.array([0,1])
|
||||
def cosine_similarity(E, F):
|
||||
norm_C = np.linalg.norm(E) # 向量a的长度
|
||||
norm_D = np.linalg.norm(F) # 向量b的长度
|
||||
return dot / (norm_C * norm_D)
|
||||
print(f"相似度 = {cosine_similarity(E, F):.3f}")
|
||||
|
||||
Reference in New Issue
Block a user