![]() ![]() ![]() Axis or Dimension: A particular dimension of a tensor.A scalar has rank 0, a vector has rank 1, a matrix is rank 2. Shape: The length (number of elements) of each of the axes of a tensor.Note: Typically, anywhere a TensorFlow function expects a Tensor as input, the function will also accept anything that can be converted to a Tensor using tf.convert_to_tensor. Tensors are used in all kinds of operations (or "Ops"). Print(a * b, "\n") # element-wise multiplication Print(a + b, "\n") # element-wise addition ]) # Could have also said `tf.ones(, dtype=tf.int32)` You can do basic math on tensors, including addition, element-wise multiplication, and matrix multiplication. Sparse tensors (see SparseTensor below).Ragged tensors (see RaggedTensor below).However, there are specialized types of tensors that can handle different shapes: The base tf.Tensor class requires tensors to be "rectangular"-that is, along each axis, every element is the same size. Tensors often contain floats and ints, but have many other types, including: You can convert a tensor to a NumPy array either using np.array or the tensor.numpy method: np.array(rank_2_tensor) There are many ways you might visualize a tensor with more than two axes. Tensors may have more axes here is a tensor with three axes: # There can be an arbitrary number of Rank_1_tensor = tf.constant()Ī "matrix" or "rank-2" tensor has two axes: # If you want to be specific, you can set the dtype (see below) at creation time A vector has one axis: # Let's make this a float tensor. # This will be an int32 tensor by default see "dtypes" below.Ī "vector" or "rank-1" tensor is like a list of values. A scalar contains a single value, and no "axes". If you're familiar with NumPy, tensors are (kind of) like np.arrays.Īll tensors are immutable like Python numbers and strings: you can never update the contents of a tensor, only create a new one. You can see all supported dtypes at tf.dtypes.DType. Tensors are multi-dimensional arrays with a uniform type (called a dtype).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |