The torch LongTensor is a tensor structure similar to a regular tensor, but it only holds integer values (32 or 64 bit). It is usually used to hold indexes and other integer-based data. The LongTensor cpu is a version of the LongTensor which is stored in the CPU memory, as opposed to CUDA memory which is stored in the GPU.
Examples: 1. Creating a LongTensor using the cpu:
import torch
x = torch.LongTensor([1, 2, 3]) # this creates a LongTensor on the CPU print(x)
Output: tensor([1, 2, 3])
2. Extracting data from a LongTensor: import torch
x = torch.LongTensor([1, 2, 3]) print(x[0]) # prints the first element of the LongTensor
This example shows how to extract a single value from a LongTensor.
Package/Library This code example makes use of the pytorch package, which is a Python library used for building and training neural networks.
Python LongTensor.cpu - 31 examples found. These are the top rated real world Python examples of torch.LongTensor.cpu extracted from open source projects. You can rate examples to help us improve the quality of examples.