利用tensorflow计算出导数时,其类型为列表的tensor,与其他单个tensor进行运算时,其结果的维度会发生变化,这里对其进行总结。
1. 网络
网络输入:x (numpy数组)
网络输出:u
主要运算:图
输出:
u: Tensor("strided_slice_72:0", shape=(?, 1), dtype=float32)
u_x: [<tf.Tensor 'gradients/concat_grad/Slice:0' shape=(?, 1) dtype=float32>]
为输出u关于输入x的一阶导
u_x2: [<tf.Tensor 'gradients/concat_grad/Slice:0' shape=(?, 1) dtype=float32>]
为输出u关于输入x的二阶导
2. 相互之间运算1:
u_x * u_x: 报错,同为装有tensorflow的列表
u_x[0] * u_x[0]: Tensor("mul_1346:0", shape=(?, 1), dtype=float32)
u * u: Tensor("mul_1347:0", shape=(?, 1), dtype=float32)
u * u_r: Tensor("mul_1348:0", shape=(1, ?, 1), dtype=float32)
u *u_r[0]: Tensor("mul_1349:0", shape=(?, 1), dtype=float32)
3. 相互之间运算2:
x: Tensor("x:0", shape=(?, 1), dtype=float32)
为placeholder的数组
xs: Tensor("xs:0", shape=(), dtype=float32_ref)
为tf.Variable(0.3, name="rs")
u / x: Tensor("truediv_55:0", shape=(?, 1), dtype=float32)
u / xs: Tensor("truediv_56:0", shape=(?, 1), dtype=float32)
u_x / x: Tensor("truediv_57:0", shape=(1, ?, 1), dtype=float32)
u_x / xs: Tensor("truediv_58:0", shape=(1, ?, 1), dtype=float32)
u_x[0] / x: Tensor("truediv_59:0", shape=(?, 1), dtype=float32)
u_x[0] / xs: Tensor("truediv_60:0", shape=(?, 1), dtype=float32)
4. 总结
①Tensor里第一个属性:add、sub由计算的最后一步操作决定;
②包含求导项(列表的tensor)时,维度会变成(1, ?, 1);
如果想让最终的tensoorflow无列表,则需要将列表tensor都取[0];
③列表型相加时,按照列表加法,会将两个列表组合起来。