From be0a8b60c9f11a8d17063ab355c331c11b8f6866 Mon Sep 17 00:00:00 2001 From: 2509165004 <2509165004@student.edu.cn> Date: Tue, 21 Apr 2026 11:21:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ; --- 1.py | 17 +++++++++++++++++ 2.py | 20 ++++++++++++++++++++ 260421-2509165004.py | 4 ++++ 3 files changed, 41 insertions(+) create mode 100644 1.py create mode 100644 2.py create mode 100644 260421-2509165004.py diff --git a/1.py b/1.py new file mode 100644 index 0000000..8eb2ebf --- /dev/null +++ b/1.py @@ -0,0 +1,17 @@ +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) \ No newline at end of file diff --git a/2.py b/2.py new file mode 100644 index 0000000..b60072c --- /dev/null +++ b/2.py @@ -0,0 +1,20 @@ +import numpy as np + +# 定义向量 +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. 计算余弦相似度 +cos_sim = np.dot(A, B) / (np.linalg.norm(A) * np.linalg.norm(B)) +print("余弦相似度 =", cos_sim) + +# 3. A = [1,0], B = [0,1]的余弦相似度 +A_new = np.array([1, 0]) +B_new = np.array([0, 1]) +cos_sim_new = np.dot(A_new, B_new) / (np.linalg.norm(A_new) * np.linalg.norm(B_new)) +print("A=[1,0], B=[0,1]的余弦相似度 =", cos_sim_new) +print("原因:两个向量正交(点积为0),方向完全垂直,所以余弦相似度为0") \ No newline at end of file diff --git a/260421-2509165004.py b/260421-2509165004.py new file mode 100644 index 0000000..961f22d --- /dev/null +++ b/260421-2509165004.py @@ -0,0 +1,4 @@ +s = "Hello" +for c in s: + print(c, ord(c)) + print(chr(65)) # 输出 A