Floating-point tensor
This tensor is used to define the elements with float type. We can create a floating-point Tensor using an integer element by using the FloatTensor property.
Syntax:
torch.FloatTensor([element1,element 2,.,element n])
Example: Python program to create float tensor and get elements.
Python3
# importing torch module import torch # create one dimensional Float Tensor with # integer type elements a = torch.FloatTensor([ 10 , 20 , 30 , 40 , 50 ]) # display data type print (a.dtype) # access elements from 0 to 3 print (a[ 0 : 3 ]) # access from 4 print (a[ 4 :]) |
Output:
torch.float32 tensor([10., 20., 30.]) tensor([50.])
One-Dimensional Tensor in Pytorch
In this article, we are going to discuss a one-dimensional tensor in Python. We will look into the following concepts:
- Creation of One-Dimensional Tensors
- Accessing Elements of Tensor
- Size of Tensor
- Data Types of Elements of Tensors
- View of Tensor
- Floating Point Tensor
Introduction
The Pytorch is used to process the tensors. Tensors are multidimensional arrays. PyTorch accelerates the scientific computation of tensors as it has various inbuilt functions.
Vector:
A vector is a one-dimensional tensor that holds elements of multiple data types. We can create vectors using PyTorch. Pytorch is available in the Python torch module. So we need to import it.
Syntax:
import pytorch