TensorLearn
Back to Course
Neural Networks: From Scratch
Module 5 of 12

5. Building the Tensor

1. The Wrapper

We wrap NumPy arrays in a Tensor class that tracks gradients.

python
class Tensor: def __init__(self, data, requires_grad=False): self.data = np.array(data) self.grad = None self.requires_grad = requires_grad self._backward = lambda: None

2. Dependency Tracking

When we add two Tensors, the result must remember its parents to backpropagate later. This forms a Directed Acyclic Graph (DAG).

Mark as Completed

TensorLearn - AI Engineering for Professionals