3-1 tensor

In the context of deep learning, tensors refer to the generalization of vectors and matrices to an arbitrary number of dimensions, as we can see in figure 3.2. Another name for the same concept is multidimensional array. The dimensionality of a tensor coincides with the number of indexes used to refer to scalar values within the tensor.

3-1 tensor_第1张图片

Compared to NumPy arrays, PyTorch tensors have a few superpowers, such as the ability to perform very fast operations on graphical processing units (GPUs), distribute operations on multiple devices or machines, and keep track of the graph of computations that created them.

1.The world as floating-point numbers
Since floating-point numbers are the way a network deals with information, we need a way to encode real-world data of the kind we want to process into something digestible by a network and then decode the output back to something we can understand and use for our purpose.

A deep neural network typically learns the transformation from one form of data to another in stages, which means the partially transformed data between each stage can be thought of as a sequence of intermediate representations.In general, such intermediate representations are collections of floating-point numbers that characterize the input and capture the data’s structure in a way that is instrumental for describing how inputs are mapped to the outputs of the neural network.

3-1 tensor_第2张图片

2.Tensors: Multidimensional arrays
(1)列表的索引访问和修改
3-1 tensor_第3张图片
3-1 tensor_第4张图片

(2)Constructing our first tensors

创建了一个以1填充大小为3的一维张量

3-1 tensor_第5张图片

创建一个3行4列的二维张量

3-1 tensor_第6张图片

我们同样可以进行索引和修改操作,索引取出的每个数都是张量形式

3-1 tensor_第7张图片

通过float可以转化为一个具体的数

3-1 tensor_第8张图片

(3)The essence of tensors

Python 列表或数字元组是单独分配在内存中的 Python 对象的集合

3-1 tensor_第9张图片
PyTorch 张量或 NumPy 数组(通常)是连续内存块上的视图

3-1 tensor_第10张图片
为张量设置具体值,以下两种方法等价

3-1 tensor_第11张图片

3-1 tensor_第12张图片

To get the coordinates of the first point(1.0 , 2.0), we do the following:

在这里插入图片描述

严格来说这只是一个二维点,而非坐标
我们可以通过二维张量来实现坐标

3-1 tensor_第13张图片

张量的访问

3-1 tensor_第14张图片

获取一个点的二维坐标
输出结果是张量,下例的新张量是一个大小为2的一维张量,它引用了b张量中第一行的值

3-1 tensor_第15张图片

3.Indexing tensors

回顾列表
3-1 tensor_第16张图片
我们可以对PyTorch张量使用相同的符号,注意对多维的处理和增维

3-1 tensor_第17张图片

你可能感兴趣的:(PyTorch,python,机器学习,人工智能,深度学习,pytorch)