Pytorch: The Number Of Sizes Provided (0) Must Be Greater Or Equal To The Number Of Dimensions In The Tensor (1)
Solution 1:
target[j, b_pact[j]]
is a single element of the tensor (a scalar, hence size of torch.Size([])
). If you want to assign anything to it, the right hand side can only be a scalar. That is not the case, as one of the terms is a tensor with 1 dimension (a vector), namely your maxq[j]
.
When specifying a dimension dim
(axis
is treated as a synonym) to torch.max
, it will return a named tuple of (values, indices)
, where values
contains the maximum values and indices
the location of each of the maximum values (equivalent to argmax).
maxq[j]
is not indexing into the maximum values, but rather the tuple of (values, indices)
. If you only want the values you can use one of the following to get the values out of the tuple (all of them are equivalent, you can use whichever you prefer):
# Destructure/unpack and ignore the indices
maxq, _ = torch.max(q_.data,axis=1)
# Access first element of the tuple
maxq = torch.max(q_.data,axis=1)[0]
# Access `values` of the named tuple
maxq = torch.max(q_.data,axis=1).values
Post a Comment for "Pytorch: The Number Of Sizes Provided (0) Must Be Greater Or Equal To The Number Of Dimensions In The Tensor (1)"