Tensorflow教程(3)什麼是張量?什麼是數據流圖?

Tensorflow = Tensor(張量) + flow(數據流圖)數組

一、張量

張量可不是「麻辣燙」!張量是一個很抽象的概念,直觀的來講,張量在tensorflow中就像一個杯子,起到保存數據的做用,咱們也能夠把張量當作一個不一樣維度的數組。spa

0階的張量是一個標量,就是一個數值;3d

1階的張量是一個向量;code

2階的張量是一個矩陣;blog

3階的張量是一個三維矩陣。教程

以此類推...class

#定義0階張量
a = tf.constant(2.,name="a")
#定義1階張量
b = tf.constant([3],name="b")
#定義2階張量
c = tf.constant([[4,5]],name="c")
print(a)
print(b)
print(c)

輸出結果:tensorflow

Tensor("a:0", shape=(), dtype=float32)
Tensor("b:0", shape=(1,), dtype=int32)
Tensor("c:0", shape=(1, 2), dtype=int32)

a、b、c三個張量分別是0階、1階、2階,能夠看出來Tensor有類型、形狀兩個屬性。float

二、數據流圖

若是你們看過官方的教程,那麼對上圖確定很熟悉。所謂Tensorflow,簡單的說,就是tensor(張量)數據在圖中flow(流動)計算的過程。im

相關文章
相關標籤/搜索