0
我有以下numpy的代碼:徵張廣播語法
# q.shape == (fxs, ks)
# E.shape == (fxs, fxs)
C = q[:, np.newaxis, :] * E[:, :, np.newaxis] * q[np.newaxis, :, :]
# C.shape == (fxs, fxs, ks)
,我在我的本徵重新實現。
這就是我想出了:
Eigen::Tensor<T, 3> C =
q.reshape(Eigen::array<int, 3> {fxs, 1, ks}).broadcast(Eigen::array<int, 3> {1, fxs, 1})
* E.reshape(Eigen::array<int, 3> {fxs, fxs, 1 }).broadcast(Eigen::array<int, 3> {1, 1, ks})
* q.reshape(Eigen::array<int, 3> {1, fxs, ks}).broadcast(Eigen::array<int, 3> {fxs, 1, 1});
但這似乎相當冗長。這是正確的翻譯?