Data Science & Machine Learning Basics
9 min
Friday, September 20, 2024
Rafiq Islam
October 16, 2024
import torch
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
print(torch.__version__)
2.3.1+cu121
Scaler
Vector
Matrix
Tensor
---
title: "PyTorch Basics"
date: "2024-10-16"
author: Rafiq Islam
categories: [Programming, Data Science, Machine Learning, Python, PyTorch]
search: true
draft": true
listing:
contents: "/../../posts"
max-items: 3
type: grid
categories: true
date-format: full
fields: [image, date, title, author, reading-time]
---
## Introduction to Tensors
```{python}
import torch
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
print(torch.__version__)
```
### Creating Tensors
- Scaler
```{python}
scaler = torch.tensor(7)
print(scaler)
print(scaler.ndim)
```
- Vector
```{python}
vec = torch.tensor([2,3,4])
print(vec.ndim)
print(vec.shape)
```
- Matrix
```{python}
MAT = torch.tensor([[2,3,4],
[3,2,6]])
MAT
```
- Tensor
```{python}
TEN = torch.tensor([[[2,3,5],
[5,4,3]]])
TEN.shape
```