Tensorflow 各基础函数使用
tf.repeat(tensor, repeats, axis=0)重复维度,扩张Tensor数据
mu = tf.random.normal([1, 2, 3])
print(mu)
mu1 = tf.repeat(mu, repeats=4, axis=0)
print(mu1)
[[[-2.2011704 1.6632527 1.052491 ]
[-0.12369094 0.29675704 -1.5922679 ]]], shape=(1, 2, 3), dtype=float32)
tf.Tensor(
[[[-2.2011704 1.6632527 1.052491 ]
[-0.12369094 0.29675704 -1.5922679 ]]
[[-2.2011704 1.6632527 1.052491 ]
[-0.12369094 0.29675704 -1.5922679 ]]
[[-2.2011704 1.6632527 1.052491 ]
[-0.12369094 0.29675704 -1.5922679 ]]
[[-2.2011704 1.6632527 1.052491 ]
[-0.12369094 0.29675704 -1.5922679 ]]], shape=(4, 2, 3), dtype=float32)
tf.transpose(tensor, [dimension_1, dimenaion_2,…,dimension_n]):这个函数主要适用于交换输入张量的不同维度用的,如果输入张量是二维,就相当是转置。输入张量是三维,可以强制更换维度。
mu = tf.random.normal([2, 2, 3])
print(mu)
mu1 = tf.transpose(mu, [0, 2, 1])
print(mu1)
tf.Tensor(
[[[ 0.6118678 -0.05129734 -1.2282405 ]
[ 0.12983456 -0.7894752 -0.5745441 ]]
[[ 0.7239799 0.3909837 -0.47409806]
[ 1.4259791 0.526061 0.13551469]]], shape=(2, 2, 3), dtype=float32)
tf.Tensor(
[[[ 0.6118678 0.12983456]
[-0.05129734 -0.7894752 ]
[-1.2282405 -0.5745441 ]]
[[ 0.7239799 1.4259791 ]
[ 0.3909837 0.526061 ]
[-0.47409806 0.13551469]]], shape=(2, 3, 2), dtype=float32)
torch : function.softmax(tensor, dim=0,1,2)