>> torch.randn((2,3), device=1)  # legacy
    

##  torch.layout  ¶

_class_ ` torch. ` ` layout ` ¶

    

A  ` torch.layout  ` is an object that represents the memory layout of a [ `
torch.Tensor  ` ](tensors.html#torch.Tensor "torch.Tensor") . Currently, we
support ` torch.strided  ` (dense Tensors) and have beta support for `
torch.sparse_coo  ` (sparse COO Tensors).

` torch.strided  ` represents dense Tensors and is the memory layout that is
most commonly used. Each strided tensor has an associated ` torch.Storage  ` ,
which holds its data. These tensors provide multi-dimensional, [ strided
](https://en.wikipedia.org/wiki/Stride_of_an_array) view of a storage. Strides
are a list of integers: the k-th stride represents the jump in the memory
necessary to go from one element to the next one in the k-th dimension of the
Tensor. This concept makes it possible to perform many tensor operations
efficiently.

Example:

    
    
    >>> x = torch.Tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
    >>> x.stride()
    (5, 1)
    
    >>> x.t().stride()
    (1, 5)
    

For more information on ` torch.sparse_coo  ` tensors, see [ torch.sparse
](sparse.html#sparse-docs) .

##  torch.memory_format  ¶

_class_ ` torch. ` ` memory_format ` ¶

    

A  ` torch.memory_format  ` is an object representing the memory format on
which a [ ` torch.Tensor  ` ](tensors.html#torch.Tensor "torch.Tensor") is or
will be allocated.

Possible values are:

  * ` torch.contiguous_format  ` : Tensor is or will be allocated in dense non-overlapping memory. Strides represented by values in decreasing order. 

  * ` torch.channels_last  ` : Tensor is or will be allocated in dense non-overlapping memory. Strides represented by values in ` strides[0]  > strides[2]  > strides[3]  > strides[1]  ==  1  ` aka NHWC order. 

  * ` torch.preserve_format  ` : Used in functions like  clone  to preserve the memory format of the input tensor. If input tensor is allocated in dense non-overlapping memory, the output tensor strides will be copied from the input. Otherwise output strides will follow ` torch.contiguous_format  `

[ Next ![](_static/images/chevron-right-orange.svg) ](tensor_view.html "Tensor
Views") [ ![](_static/images/chevron-right-orange.svg) Previous ](tensors.html
"torch.Tensor")

* * *

© Copyright 2019, Torch Contributors.

Built with [ Sphinx ](http://sphinx-doc.org/) using a [ theme
](https://github.com/rtfd/sphinx_rtd_theme) provided by [ Read the Docs
](https://readthedocs.org) .

  * Tensor Attributes 
    * torch.dtype 
    * torch.device 
    * torch.layout 
    * torch.memory_format 

![](https://www.googleadservices.com/pagead/conversion/795629140/?label=txkmCPmdtosBENSssfsC&guid=ON&script=0)

##  Docs

Access comprehensive developer documentation for PyTorch

[ View Docs ](https://pytorch.org/docs/stable/index.html)

##  Tutorials

Get in-depth tutorials for beginners and advanced developers

[ View Tutorials ](https://pytorch.org/tutorials)

##  Resources

Find development resources and get your questions answered

[ View Resources ](https://pytorch.org/resources)

[ ](https://pytorch.org/)

  * [ PyTorch ](https://pytorch.org/)
  * [ Get Started ](https://pytorch.org/get-started)
  * [ Features ](https://pytorch.org/features)
  * [ Ecosystem ](https://pytorch.org/ecosystem)
  * [ Blog ](https://pytorch.org/blog/)
  * [ Contributing ](https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md)

  * [ Resources ](https://pytorch.org/resources)
  * [ Tutorials ](https://pytorch.org/tutorials)
  * [ Docs ](https://pytorch.org/docs/stable/index.html)
  * [ Discuss ](https://discuss.pytorch.org)
  * [ Github Issues ](https://github.com/pytorch/pytorch/issues)
  * [ Brand Guidelines ](https://pytorch.org/assets/brand-guidelines/PyTorch-Brand-Guidelines.pdf)

  * Stay Connected 
  * Email Address 

[ ](https://www.facebook.com/pytorch) [ ](https://twitter.com/pytorch) [
](https://www.youtube.com/pytorch)

To analyze traffic and optimize your exper