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

  • Mastering TensorFlow 1.x
  • Armando Fandango
  • 354字
  • 2021-06-25 22:50:54

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.

主站蜘蛛池模板: 河西区| 紫云| 禄丰县| 珠海市| 绥中县| 利辛县| 仁布县| 澳门| 佛山市| 长岭县| 大冶市| 海林市| 萍乡市| 潜江市| 望谟县| 汪清县| 枝江市| 海阳市| 桑日县| 青浦区| 宾川县| 犍为县| 乐亭县| 仁布县| 西丰县| 荣昌县| 曲周县| 固始县| 伊川县| 徐州市| 侯马市| 家居| 海口市| 赤峰市| 高尔夫| 琼海市| 两当县| 嘉义县| 阿坝县| 大姚县| 安国市|