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

PyTorch torch.empty_strided function

PyTorch torch.empty_strided function


PyTorch torch reference manual PyTorch torch reference manual

torch.empty_strided is a PyTorch function for creating an uninitialized tensor with a specified stride.

Function definition

torch.empty_strided(size, stride, dtype=None, device=None, requires_grad=False)


Usage examples

Example

import

torch

Create a tensor with shape (3, 4) and stride (1, 3)

x

=

torch.

empty_strided

(

(

3

,

4

)

,

(

1

,

3

)

)

print

(

x

)

print

(

"Shape:"

,

x.

shape

)

print

(

"Stride:"

,

x.

stride

(

)

)

print

(

"Note: values are uninitialized memory values"

)


PyTorch torch reference manual PyTorch torch reference manual