Files
task-3-2-1-Text-Processing-…/1
2509165045 64a2de73d8 作业10
2026-04-21 11:30:19 +08:00

39 lines
1.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#第一题
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}")