Add element-wise division of tensors

This commit is contained in:
Aodhnait Étaín 2020-11-15 21:52:34 +00:00
parent d39a843ef9
commit f182af0cdd

View file

@ -48,6 +48,17 @@ class Tensor:
tensor._back = back
return tensor
def div(self, other):
tensor = Tensor(self.value / other.value)
tensor._save(self, other)
def back(upstream):
a, b = tensor._parents
return 1 / np.dot(b.value, upstream), -a.value / np.dot(b.value ** 2, upstream)
tensor._back = back
return tensor
def expt(self, exponent):
tensor = Tensor(self.value ** exponent)
tensor._save(self)