学习笔记——张量(tensor)

用深度学习框架的时候老是看到 tensor,决定仔细的研究一下这是个什么。

张量是一种表示物理量的方式,这个方式就是用基向量与分量组合表示物理量(Combinationof basis vector and component)。

Rank 为 0 的叫标量;Rank 为 1 的叫向量,也叫 1 阶张量;Rank 为 2 的叫矩阵,也叫 2 阶张量。Rank 再往上就是 4,5,6 … 阶张量。

理解参考:

keras 的官方例程里提到 tensor:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from keras.layers import Input, Dense
from keras.models import Model

# This returns a tensor
inputs = Input(shape=(784,))

# a layer instance is callable on a tensor, and returns a tensor
x = Dense(64, activation='relu')(inputs)
x = Dense(64, activation='relu')(x)
predictions = Dense(10, activation='softmax')(x)

# This creates a model that includes
# the Input layer and three Dense layers
model = Model(inputs=inputs, outputs=predictions)
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
model.fit(data, labels) # starts training

根据图理解 tensor (来源Alt text Alt text Alt text