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

PyTorch torch.sparse_csc_tensor function

PyTorch torch.sparse_csc_tensor function


PyTorch torch reference manual PyTorch torch reference manual

torch.sparse_csc_tensor is a function in PyTorch used to construct a sparse CSC (compressed sparse column) tensor.

Function definition

torch.sparse_csc_tensor(ccol_indices, row_indices, values, size=None, dtype=None, device=None, requires_grad=False)


Usage examples

Example

import

torch

Create a sparse CSC tensor

Column pointers

ccol_indices

=

torch.

tensor

(

[

0

,

1

,

2

,

3

]

)

Row indices

row_indices

=

torch.

tensor

(

[

0

,

1

,

2

,

0

]

)

Value

values

=

torch.

tensor

(

[

1.0

,

2.0

,

3.0

,

4.0

]

)

Tensor size

size

=

(

3

,

3

)

Construct a sparse CSC tensor

x

=

torch.

sparse_csc_tensor

(

ccol_indices

,

row_indices

,

values

,

size

)

print

(

x

)

print

(

"Dense tensor:"

)

print

(

x.

to_dense

(

)

)


PyTorch torch reference manual PyTorch torch reference manual