Skip to content

Commit d775598

Browse files
author
yu2nshuai
committed
update
1 parent 22c3ec4 commit d775598

File tree

3 files changed

+470
-27
lines changed

3 files changed

+470
-27
lines changed

01_TensorFlow_basics/01_01_Tensors.ipynb

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"metadata": {},
1717
"outputs": [],
1818
"source": [
19-
"#>>>>>>>>>>>>>>>>>1、基础知识>>>>>>>>>>>>>>>>>>>>>>>>>\n",
19+
"### 1.1.1 基础知识\n",
2020
"#张量是具有统一类型(称为 dtype)的多维数组.您可以在 tf.dtypes.DType 中查看所有支持的 dtypes。\n",
2121
"#如果您熟悉 NumPy,就会知道张量与 np.arrays 有一定的相似性。\n",
2222
"#就像 Python 数值和字符串一样,所有张量都是不可变的:永远无法更新张量的内容,只能创建新的张量。\n"
@@ -36,7 +36,7 @@
3636
}
3737
],
3838
"source": [
39-
"#下面是一个“标量”(或称“0 秩”张量)。标量包含单个值,但没有“轴”。\n",
39+
"##下面是一个“标量”(或称“0 秩”张量)。标量包含单个值,但没有“轴”。\n",
4040
"# This will be an int32 tensor by default; see \"dtypes\" below.\n",
4141
"rank_0_tensor = tf.constant(4)\n",
4242
"print(rank_0_tensor)"
@@ -56,7 +56,7 @@
5656
}
5757
],
5858
"source": [
59-
"#“向量”(或称“1 秩”张量)就像一个值列表。向量有 1 个轴:\n",
59+
"##“向量”(或称“1 秩”张量)就像一个值列表。向量有 1 个轴:\n",
6060
"# Let's make this a float tensor.\n",
6161
"rank_1_tensor = tf.constant([2.0,3.0,4.0])\n",
6262
"print(rank_1_tensor)"
@@ -79,7 +79,7 @@
7979
}
8080
],
8181
"source": [
82-
"#“矩阵”(或称“2 秩”张量)有 2 个轴:\n",
82+
"##“矩阵”(或称“2 秩”张量)有 2 个轴:\n",
8383
"# If you want to be specific, you can set the dtype (see below) at creation time\n",
8484
"rank_2_tensor = tf.constant(\n",
8585
" [[1,2],\n",
@@ -243,7 +243,7 @@
243243
}
244244
],
245245
"source": [
246-
"#各种运算都可以使用张量。\n",
246+
"##各种运算都可以使用张量。\n",
247247
"#tf.reduce_max 是 TensorFlow 中的一个函数,用于计算张量(tensor)中的最大值。它可以沿着张量的一个或多个维度进行操作。\n",
248248
"a = tf.constant([\n",
249249
" [1,2,3,4,5],\n",
@@ -326,7 +326,7 @@
326326
}
327327
],
328328
"source": [
329-
"#>>>>>>>>>>>>>>>>>2、SHAPE>>>>>>>>>>>>>>>>>>>>>>>>>\n",
329+
"### 1.1.2 SHAPE\n",
330330
"\n",
331331
"##张量有形状。下面是几个相关术语:\n",
332332
"\n",
@@ -440,8 +440,8 @@
440440
}
441441
],
442442
"source": [
443-
"#>>>>>>>>>>>>>>>>>3、索引>>>>>>>>>>>>>>>>>>>>>>>>>\n",
444-
"#单轴索引\n",
443+
"### 1.1.3 索引\n",
444+
"##单轴索引\n",
445445
"#TensorFlow 遵循标准 Python 索引编制规则(类似于在 Python 中为列表或字符串编制索引)以及 NumPy 索引编制的基本规则。\n",
446446
"#索引从 0 开始编制\n",
447447
"#负索引表示按倒序编制索引\n",
@@ -483,7 +483,7 @@
483483
}
484484
],
485485
"source": [
486-
"#多轴索引\n",
486+
"##多轴索引\n",
487487
"#更高秩的张量通过传递多个索引来编制索引。\n",
488488
"\n",
489489
"#对于高秩张量的每个单独的轴,遵循与单轴情形完全相同的规则。\n",
@@ -513,8 +513,8 @@
513513
}
514514
],
515515
"source": [
516-
"#>>>>>>>>>>>>>>>>>4、reshape>>>>>>>>>>>>>>>>>>>>>>>>>\n",
517-
"#改变张量的形状很有用\n",
516+
"### 1.1.4 reshape\n",
517+
"##改变张量的形状很有用\n",
518518
"# Shape returns a `TensorShape` object that shows the size along each axis\n",
519519
"x = tf.constant([[1],[2],[3]])\n",
520520
"print(x,\"\\n\")\n",
@@ -691,7 +691,7 @@
691691
}
692692
],
693693
"source": [
694-
"#>>>>>>>>>>>>>>>>>5、DTypes>>>>>>>>>>>>>>>>>>>>>>>>>\n",
694+
"### 1.1.5 DTypes\n",
695695
"#使用 Tensor.dtype 属性可以检查 tf.Tensor 的数据类型。\n",
696696
"#从 Python 对象创建 tf.Tensor 时,您可以选择指定数据类型。\n",
697697
"#如果不指定,TensorFlow 会选择一个可以表示您的数据的数据类型。TensorFlow 将 Python 整数转换为 tf.int32,\n",
@@ -723,8 +723,9 @@
723723
}
724724
],
725725
"source": [
726-
"#>>>>>>>>>>>>>>>>>6、广播>>>>>>>>>>>>>>>>>>>>>>>>>\n",
727-
"#广播是从 NumPy 中的等效功能借用的一个概念。简而言之,在一定条件下,对一组张量执行组合运算时,为了适应大张量,会对小张量进行“扩展”。\n",
726+
"### 1.1.6 广播\n",
727+
"#广播是从 NumPy 中的等效功能借用的一个概念。简而言之,在一定条件下,对一组张量执行组合运算时,\n",
728+
"#为了适应大张量,会对小张量进行“扩展”。\n",
728729
"\n",
729730
"#最简单和最常见的例子是尝试将张量与标量相乘或相加。在这种情况下会对标量进行广播,使其变成与其他参数相同的形状。\n",
730731
"x = tf.constant([1,2,3])\n",
@@ -824,7 +825,7 @@
824825
}
825826
],
826827
"source": [
827-
"#>>>>>>>>>>>>>>>>>7、tf.convert_to_tensor>>>>>>>>>>>>>>>>>>>>>>>>>\n",
828+
"### 1.1.7 tf.convert_to_tensor\n",
828829
"#大部分运算(如 tf.matmul 和 tf.reshape)会使用 tf.Tensor 类的参数。不过,在上面的示例中,\n",
829830
"# 您会发现形状类似于张量的 Python 对象也可以接受。\n",
830831
"\n",
@@ -843,7 +844,7 @@
843844
"metadata": {},
844845
"outputs": [],
845846
"source": [
846-
"#>>>>>>>>>>>>>>>>>8、不规则张量>>>>>>>>>>>>>>>>>>>>>>>>>\n",
847+
"### 1.1.8 不规则张量\n",
847848
"#如果张量的某个轴上的元素个数可变,则称为“不规则”张量。对于不规则数据,请使用 tf.ragged.RaggedTensor。\n",
848849
"#例如,下面的例子无法用规则张量表示:\n"
849850
]
@@ -944,7 +945,7 @@
944945
}
945946
],
946947
"source": [
947-
"#>>>>>>>>>>>>>>>>>9、字符串张量>>>>>>>>>>>>>>>>>>>>>>>>>\n",
948+
"### 1.1.9 字符串张量\n",
948949
"#tf.string 是一种 dtype,也就是说,在张量中,您可以用字符串(可变长度字节数组)来表示数据。\n",
949950
"\n",
950951
"#字符串是原子类型,无法像 Python 字符串一样编制索引。字符串的长度并不是张量的一个轴。\n",
@@ -1117,7 +1118,7 @@
11171118
"metadata": {},
11181119
"outputs": [],
11191120
"source": [
1120-
"#>>>>>>>>>>>>>>>>>10、稀疏张量>>>>>>>>>>>>>>>>>>>>>>>>>\n",
1121+
"### 1.1.10 稀疏张量\n",
11211122
"#在某些情况下,数据很稀疏,比如说在一个非常宽的嵌入空间中。\n",
11221123
"# 为了高效存储稀疏数据,TensorFlow 支持 tf.sparse.SparseTensor 和相关运算。"
11231124
]
@@ -1185,13 +1186,6 @@
11851186
"# You can convert sparse tensors to dense\n",
11861187
"tf.sparse.to_dense(sparse_tensor)\n"
11871188
]
1188-
},
1189-
{
1190-
"cell_type": "code",
1191-
"execution_count": null,
1192-
"metadata": {},
1193-
"outputs": [],
1194-
"source": []
11951189
}
11961190
],
11971191
"metadata": {

0 commit comments

Comments
 (0)