# Imports (note that you also need imports from the .py function files)
importnumpyasnp
importtorch# PyTorch / ML tool
```
%% Cell type:markdown id: tags:
# Tensors*
Tensors are basically n-dimensional arrays similar to numpy ndarrays with additional functionalities, which make them very useful for machine-learning tasks.
*Note: Some tasks here can also be done using standard np.arrays.*
**Below, look at some features of tensors**:
%% Cell type:markdown id: tags:
## GPU Support
Tensors **computations can be conducted on the GPU** (and also CPU).
For this, we need to move the data to the computing device.
*Note*: This will only work when a GPU is available
%% Cell type:code id: tags:
``` python
# Identify available devices: Take GPU if available, else CPU
*Note*: When training a neural net, the backpropagation algorithm will compute the gradients as above and then update the trainable parameters using e.g. stochastic gradient descent.
%% Cell type:code id: tags:
``` python
a=torch.tensor(1.5,requires_grad=True)
b=a**2
c=5*b
c.backward()
print(a.grad)
```
%% Cell type:markdown id: tags:
## Conversion to numpy
Tensors and np.ndarrays **can be converted** to each other (without the gradient information).