From c39c151794204b8bea3ff058418fab1345c4a32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=A5=A0=E6=A5=A0?= <2509165032@student.example.com> Date: Tue, 21 Apr 2026 11:23:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hh.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 hh.py diff --git a/hh.py b/hh.py new file mode 100644 index 0000000..d423b34 --- /dev/null +++ b/hh.py @@ -0,0 +1,64 @@ +# 文本在计算机中的存储方式 +text = "Hello" + +# 如果我们看它的"数字形式": +print([ord(c) for c in text]) +# 输出: [72, 101, 108, 108, 111] +# 72='H', 101='e', 108='l', 111='o' + +# 中文例子 +text_cn = "你好" +print([ord(c) for c in text_cn]) +# 输出: [20320, 22909] +# 20320='你', 22909='好' +import numpy as np + +# 一维向量 +v1 = np.array([3]) # 只有1个数字 +print(f"v1 = {v1}") + +# 二维向量 +v2 = np.array([2, 3]) # 2个数字,表示平面上的一个点 +print(f"v2 = {v2}") + +# 三维向量 +v3 = np.array([1, 2, 3]) # 3个数字,表示立体空间的一个点 +print(f"v3 = {v3}") + +# 更多维向量(机器学习中常用) +v100 = np.array([0.1, 0.5, -0.3, 0.8, ...]) # 100维! +print(f"v100有 {len(v100)} 个元素") +import numpy as np + +# 向量加法:对应位置相加 +a = np.array([1, 2, 3]) +b = np.array([4, 5, 6]) +c = a + b # [1+4, 2+5, 3+6] = [5, 7, 9] + +print(f"a + b = {c}") # [5, 7, 9] + +# 直观理解: +# a = [1, 2, 3] 从原点出发走1步、再走2步、再走3步 +# b = [4, 5, 6] 从原点出发走4步、再走5步、再走6步 +# a + b = 从原点走完a再走b = [5, 7, 9] +# 向量乘以一个数字(标量) +v = np.array([1, 2, 3]) +result = v * 2 # [1*2, 2*2, 3*2] = [2, 4, 6] + +print(f"v * 2 = {result}") # [2, 4, 6] + +# 直观理解: +# v = [1, 2, 3] 表示"方向" +# v * 2 = [2, 4, 6] 方向不变,长度变成2倍 +# 两个向量对应位置相乘,然后加起来 +a = np.array([1, 2, 3]) +b = np.array([4, 5, 6]) + +# 点积计算过程: +# 1*4 + 2*5 + 3*6 = 4 + 10 + 18 = 32 + +dot = np.dot(a, b) +print(f"点积 = {dot}") # 32 + +# 或者用 @ 运算符 +print(f"a @ b = {a @ b}") # 32