fork download
  1. import tensorflow as tf
  2.  
  3. # 0D Tensor (scalar)
  4. scalar = tf.constant(7)
  5. print(scalar)
  6.  
  7. # 1D Tensor (vector)
  8. vector = tf.constant([1, 2, 3])
  9. print(vector)
  10.  
  11. # 2D Tensor (matrix)
  12. matrix = tf.constant([[1, 2], [3, 4]])
  13. print(matrix)
  14.  
  15. # 3D Tensor
  16. tensor_3d = tf.constant([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
  17. print(tensor_3d)
  18.  
Success #stdin #stdout 1.6s 197892KB
stdin
Standard input is empty
stdout
Tensor("Const:0", shape=(), dtype=int32)
Tensor("Const_1:0", shape=(3,), dtype=int32)
Tensor("Const_2:0", shape=(2, 2), dtype=int32)
Tensor("Const_3:0", shape=(2, 2, 2), dtype=int32)