首页 > 解决方案 > CNTK - reshape an axis to matrix

问题描述

Given a Tensor whose shape is known only at the compute time, how to convert a Tensor of shape, for e.g., (n1, n2, m*n) to (n1, n2, m, n) assuming there is a prior condition that, the last dimension is strictly a multiple of n.

标签: cntk

解决方案


因为,我们拥有的唯一信息是最后一个维度是 n 的倍数,所以下面的代码行就可以解决问题。这里,x 是一个张量变量,其形状是在网络编译时计算的。

x = C.reshape(x, x.shape[:-1] + (-1, n))


推荐阅读