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

Tensors

Tensors are the basic components in TensorFlow. A tensor is a multidimensional collection of data elements. It is generally identified by shape, type, and rank. Rank refers to the number of dimensions of a tensor, while shape refers to the size of each dimension. You may have seen several examples of tensors before, such as in a zero-dimensional collection (also known as a scalar), a one-dimensional collection (also known as a vector), and a two-dimensional collection (also known as a matrix).

A scalar value is a tensor of rank 0 and shape []. A vector, or a one-dimensional array, is a tensor of rank 1 and shape [number_of_columns] or [number_of_rows]. A matrix, or a two-dimensional array, is a tensor of rank 2 and shape [number_of_rows, number_of_columns]. A three-dimensional array is a tensor of rank 3. In the same way, an n-dimensional array is a tensor of rank n.

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

The data types that can be found in the TensorFlow library are described at the following link:  https://www.tensorflow.org/api_docs/python/tf/DType.

The following are the most commonly used data types in TensorFlow:

Use TensorFlow data types for defining tensors i nstead of native data types from Python or data types from NumPy.

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, NumPy arrays, and pandas DataFrames, with the tf.convert_to_tensor() function

Let's explore different ways of creating Tensors.

主站蜘蛛池模板: 黑山县| 开江县| 沙河市| 巴林右旗| 吉安市| 成都市| 敖汉旗| 盘锦市| 宁强县| 桃江县| 醴陵市| 金乡县| 大英县| 湖州市| 玉林市| 马边| 浦东新区| 金平| 金华市| 余干县| 蓬安县| 罗城| 庆安县| 梅州市| 铜川市| 大港区| 巴林左旗| 白朗县| 青铜峡市| 樟树市| 敦化市| 新丰县| 旺苍县| 阜阳市| 罗山县| 新田县| 沂源县| 集贤县| 昔阳县| 盐山县| 弥勒县|