用星号操作员重塑`*`p pytorch
在阅读
def extract(a, t, x_shape):
batch_size = t.shape[0]
out = a.gather(-1, t.cpu())
return out.reshape(batch_size, *((1,) * (len(x_shape) - 1))).to(t.device)
,这是最终的返回语句,*((1,)
均值含义reshape
函数?打开操作员?如果是,这里如何使用?
While reading this annotated implementation of Diffusion Probabilistic models in PyTorch, I got stuck at understanding this function
def extract(a, t, x_shape):
batch_size = t.shape[0]
out = a.gather(-1, t.cpu())
return out.reshape(batch_size, *((1,) * (len(x_shape) - 1))).to(t.device)
What it's not clear it's the final return statement, what does the *((1,)
mean into reshape
function? Does that asterisk correspond to the unpacking operator? And if yes, how is it used here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
意味着创建一个带长度
len(x_shape)的元组 - 1
填充仅1
s的意思是将元组扩展到参数中
,因此最终会变成(例如
len) (x_shape)
== 5)means to create a tuple with length
len(x_shape) - 1
filled with just1
smeans to spread the tuple into arguments
So it ends up being (say
len(x_shape)
== 5)