### Related videos

How To Play Michaels Cue BidA scalar contains a single value, and no "axes". You can convert a tensor to a NumPy array either using np. The base tf. Tensor class requires tensors to be "rectangular"that is, along each axis, every element is the same size. However, there are specialized types of Tensors that can handle different shapes:. We can do basic math on tensors, including addition, element-wise multiplication, and matrix multiplication.

Tensors and tf. TensorShape objects have convenient properties for accessing these:. While axes are often referred to by their indices, you should always keep track of the meaning of each. Often axes are ordered from global to local: The batch axis first, followed by spatial dimensions, and features for each location last.

This way feature vectors are contiguous regions of memory. TensorFlow follow standard python indexing rules, similar to indexing a list or a string in python , and the bacic rules for numpy indexing.

The tf. You can reshape a tensor into a new shape. Reshaping is fast and cheap as the underlying data does not need to be duplicated. The data maintains it's layout in memory and a new tensor is created, with the requested shape, pointing to the same data.

TensorFlow uses C-style "row-major" memory ordering, where incrementing the right-most index corresponds to a single step in memory. Typically the only reasonable uses of tf. For this 3x2x5 tensor, reshaping to 3x2 x5 or 3x 2x5 are both reasonable things to do, as the slices do not mix:. Reshaping will "work" for any new shape with the same total number of elements, but it will not do anything useful if you do not respect the order of the axes.

Swapping axes in tf. You may run across not-fully-specified shapes. Either the shape contains a None a dimension's length is unknown or the shape is None the rank of the tensor is unknown. Except for tf. To inspect a tf. Tensor 's data type use the Tensor. When creating a tf. Tensor from a Python object you may optionally specify the datatype.

If you don't, TensorFlow chooses a datatype that can represent your data. TensorFlow converts Python integers to tf. Otherwise TensorFlow uses the same rules NumPy uses when converting to arrays. Broadcasting is a concept borrowed from the equivalent feature in NumPy. In short, under certain conditions, smaller tensors are "stretched" automatically to fit larger tensors when running combined operations on them.

The simplest and most common case is when you attempt to multiply or add a tensor to a scalar. In that case, the scalar is broadcast to be the same shape as the other argument.

Likewise, 1-sized dimensions can be stretched out to match the other arguments. Both arguments can be stretched in the same computation. In this case a 3x1 matrix is element-wise multiplied by a 1x4 matrix to produce a 3x4 matrix.

Note how the leading 1 is optional: The shape of y is [4]. Most of the time, broadcasting is both time and space efficient, as the broadcast operation never materializes the expanded tensors in memory. You see what broadcasting looks like using tf. Here, you are materializing the tensor. It can get even more complicated. Most ops, like tf. However, you'll notice in the above case, we frequently pass Python objects shaped like tensors.

Give yourself an additional incentive to complete the course. EdX, a non-profit, relies on verified certificates to help fund free education for everyone globally. Video Transcript:. Course Type:. Share this course Share this course on facebook Share this course on twitter Share this course on linkedin Share this course via email. Prerequisites Introductory chemistry and physics A basic understanding of matrix algebra.

About this course Skip About this course. FAQ Who can register for this course? Meet your instructors Massachusetts Institute of Technology.

Eugene Fitzgerald Merton C.

You have hit the mark. In it something is also idea good, agree with you.