- 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:
- Tensors page on Wikipedia, at https://en.wikipedia.org/wiki/Tensor
- Introduction to Tensors guide from NASA, at https://www.grc.nasa.gov/www/k-12/Numbers/Math/documents/Tensors_TM2002211716.pdf
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.
- 觸摸屏實(shí)用技術(shù)與工程應(yīng)用
- Learning Cocos2d-x Game Development
- 顯卡維修知識(shí)精解
- 極簡(jiǎn)Spring Cloud實(shí)戰(zhàn)
- BeagleBone By Example
- 硬件產(chǎn)品經(jīng)理成長(zhǎng)手記(全彩)
- Camtasia Studio 8:Advanced Editing and Publishing Techniques
- 計(jì)算機(jī)組裝與維護(hù)(第3版)
- 筆記本電腦維修300問
- 基于Proteus仿真的51單片機(jī)應(yīng)用
- BeagleBone Robotic Projects
- 筆記本電腦維修實(shí)踐教程
- 電腦組裝與維護(hù)即時(shí)通
- FreeSWITCH Cookbook
- 電腦軟硬件維修寶典