Add element-wise division of tensors
This commit is contained in:
parent
d39a843ef9
commit
f182af0cdd
|
@ -48,6 +48,17 @@ class Tensor:
|
||||||
tensor._back = back
|
tensor._back = back
|
||||||
return tensor
|
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):
|
def expt(self, exponent):
|
||||||
tensor = Tensor(self.value ** exponent)
|
tensor = Tensor(self.value ** exponent)
|
||||||
tensor._save(self)
|
tensor._save(self)
|
||||||
|
|
Loading…
Reference in a new issue