我是一个Python/Pytorch用户。首先,假设我有一个大小为LxL的数组M,在numpy中,我想要得到以下数组:A=(M,...,M),大小为NxLxL,有没有比以下方法更优雅/更节省内存的方式:
A=np.array([M]*N) ?
有关torch张量的相同问题! 现在,如果M是一个Variable(torch.tensor),我必须执行以下操作:
A=torch.autograd.Variable(torch.tensor(np.array([M]*N)))
which is ugly !
numpy
hastile
andrepeat
. Using them may requireM[None,...]
- hpaulj