From fda2a2e954006242889152dc190cce9ee29130d7 Mon Sep 17 00:00:00 2001 From: 2509165014 <2509165014@student.edu.cn> Date: Tue, 21 Apr 2026 11:23:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fps.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 fps.py diff --git a/fps.py b/fps.py new file mode 100644 index 0000000..cad8723 --- /dev/null +++ b/fps.py @@ -0,0 +1,44 @@ +for c in "Hello": + print(c,ord(c)) + print(chr(65)) +# 数据表示形式:图像以数值矩阵(像素值)存储,是结构化的数值数据,计算机可以直接用数学运算(卷积、矩阵计算)处理;而文本是符号序列,是非结构化的字符数据,需要额外编码(如词向量)才能转为数值,无法直接用简单矩阵运算处理。 +# 语义理解:图像的语义基于视觉特征(边缘、颜色、纹理),规律相对直观;文本语义依赖上下文、语法、文化背景等,具有歧义性和抽象性,计算机很难像人类一样理解自然语言的深层含义。 +#向量基础 +import numpy as np + +# 定义向量 +A = np.array([3, 4]) +B = np.array([1, 2]) + +# 1. 计算A + B +add_result = A + B +print("A + B =", add_result) + +# 2. 计算2 × A +mul_result = 2 * A +print("2 × A =", mul_result) + +# 3. 计算A的长度(模) +norm_A = np.linalg.norm(A) +print("A的长度(模) =", norm_A) +import numpy as np +from numpy.linalg import norm + +# 定义向量 +A = np.array([1, 2, 3]) +B = np.array([4, 5, 6]) + +# 1. 计算点积A·B +dot_product = np.dot(A, B) +print("A·B =", dot_product) + +# 2. 计算余弦相似度 +cosine_similarity = np.dot(A, B) / (norm(A) * norm(B)) +print("余弦相似度 =", cosine_similarity) + +# 3. 向量A = [1, 0],B = [0, 1]的余弦相似度 +A_new = np.array([1, 0]) +B_new = np.array([0, 1]) +cosine_similarity_new = np.dot(A_new, B_new) / (norm(A_new) * norm(B_new)) +print("新向量的余弦相似度 =", cosine_similarity_new) +print("原因:两个向量相互垂直(正交),点积为0,因此余弦相似度为0") \ No newline at end of file