官术网_书友最值得收藏!

Tensors

Tensors are the basic elements of computation and a fundamental data structure in TensorFlow. Probably the only data structure that you need to learn to use TensorFlow. A tensor is an n-dimensional collection of data, identified by rank, shape, and type.

Rank is the number of dimensions of a tensor, and shape is the list denoting the size in each dimension. A tensor can have any number of dimensions. You may be already familiar with quantities that are a zero-dimensional collection (scalar), a one-dimensional collection (vector), a two-dimensional collection (matrix), and a multidimensional collection.

A scalar value is a tensor of rank 0 and thus has a shape of [1]. A vector or a one-dimensional array is a tensor of rank 1 and has a shape of [columns] or [rows]. A matrix or a two-dimensional array is a tensor of rank 2 and has a shape of [rows, columns]. A three-dimensional array would be a tensor of rank 3, and in the same manner, an n-dimensional array would be a tensor of rank n.

Refer to the following resources to learn more about tensors and their mathematical underpinnings:

A tensor can store data of one type in all its dimensions, and the data type of its elements is known as the data type of the tensor.

You can also check the data types defined in the latest version of the TensorFlow library at https://www.tensorflow.org/api_docs/python/tf/DType.

At the time of writing this book, the TensorFlow had the following data types defined:

We recommend that you should avoid using the Python native data types. Instead of the Python native data types, use TensorFlow data types for defining tensors.

Tensors can be created in the following ways:

  • By defining constants, operations, and variables, and passing the values to their constructor.
  • By defining placeholders and passing the values to session.run().
  • By converting Python objects such as scalar values, lists, and NumPy arrays with the tf.convert_to_tensor() function.

Let's examine different ways of creating Tensors.

主站蜘蛛池模板: 鄄城县| 永登县| 曲沃县| 克东县| 兴宁市| 肥东县| 龙陵县| 阜新| 章丘市| 衡山县| 平南县| 广昌县| 清远市| 元阳县| 双流县| 武汉市| 安吉县| 海淀区| 遂溪县| 乌拉特后旗| 郑州市| 涟水县| 东兴市| 邯郸县| 视频| 阿拉善盟| 平舆县| 盈江县| 西林县| 信阳市| 武城县| 乐陵市| 义马市| 舟山市| 大同县| 深水埗区| 白河县| 砚山县| 盈江县| 新邵县| 永寿县|