Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.scatter function

PyTorch torch.scatter function


PyTorch torch reference manual PyTorch torch reference manual

torch.scatter is a function in PyTorch used to scatter values to specified positions.

Function definition

torch.scatter(input, dim, index, src, reduce)


Usage examples

Example

import

torch

x

=

torch.

zeros

(

3

,

4

)

Scatter values to specified positions

index

=

torch.

tensor

(

[

[

0

]

,

[

1

]

,

[

2

]

]

)

src

=

torch.

tensor

(

[

[

1

,

2

,

3

,

4

]

,

[

5

,

6

,

7

,

8

]

,

[

9

,

10

,

11

,

12

]

]

)

result

=

torch.

scatter

(

x

,

dim

=

0

,

index

=

index

,

src

=

src

)

print

(

result

)


PyTorch torch reference manual PyTorch torch reference manual