close
在 TensorFlow 中,基本資料結構是由所謂的 tensor 來建立的。
- 官方網站中, tensor 的定義如下:
A tensor consists of a set of primitive values shaped into an array of any number of dimensions.
主要由三個參數構成,分別是 rank (維度),shape (資料大小: 幾行幾列),type (資料型別)。
在官方網站的範例中,可以理解參數的意義。
# a rank 0 tensor; this is a scalar with shape []
3
# a rank 1 tensor; this is a vector with shape [3]
[1. ,2., 3.]
# a rank 2 tensor; a matrix with shape [2, 3]
[[1., 2., 3.], [4., 5., 6.]]
[[1., 2., 3.], [4., 5., 6.]]
# a rank 3 tensor with shape [2, 1, 3]
[[[1., 2., 3.]], [[7., 8., 9.]]]
- 我們可以利用上述的定義,產生一個具浮點數特性的 tensor,
node1 = tf.constant(3.0, tf.float32)
並且嘗試將它的值印出,
print(node1)
會發現跟我們預期的結果不同,並不是輸出 3.0 這個值。
Tensor("Const:0", shape=(), dtype=float32)
從輸出結果告訴我們,存在一個常數浮點數的 tensor,維度是 0,資料型別是 float32
該如何印出我們想要的值,需要等待下一篇文章介紹所謂的 computational graph,再來解答了。
文章標籤
全站熱搜
留言列表