SciTech-BigDataAIML-Tensorflow-Introduction to Tensors

发布时间 2023-12-31 20:58:25作者: abaelhe

https://tensorflow.google.cn/guide/tensor

Introduction to Tensors

  • Tensors are multi-dimensional arrays with a uniform type (called a dtype). tf.dtypes included all supported dtypes.
    If you're familiar with NumPy, tensors are (kind of) like np.arrays.
  • All tensors are immutable and only create a new one, just like Python numbers and strings: you can never update the contents of a tensor.

About shapes
Tensors have shapes. Some vocabulary:

  • Shape: The length (number of elements) of each of the axes of a tensor.
  • Rank: Number of tensor axes:
    • A scalar has rank 0,
    • a vector has rank 1,
    • a matrix is rank 2.
  • Axis or Dimension: A particular dimension of a tensor.
  • Size: The total number of items in the tensor, the product of the shape vector's elements.

Note: Although you may see reference to a "tensor of two dimensions", a rank-2 tensor does not usually describe a 2D space.
Tensors and tf.TensorShape objects have convenient properties for accessing these: