把一个tensor变成和函数括号内一样形状的tensor,用法与expand()类似
-
>>> x = torch.tensor([[
1], [
2], [
3]])
-
>>> x.size()
-
torch.Size([
3,
1])
-
>>> x.expand(
3,
4)
-
tensor([[
1,
1,
1,
1],
-
[
2,
2,
2,
2],
-
[
3,
3,
3,
3]])
-
>>> x.expand(
-1,
4)
# -1 means not changing the size of that dimension
-
tensor([[
1,
1,
1,
1],
-
[
2,
2,
2,
2],
-
[
3,
3,
3,
3]])