diff --git a/Mahendra/task1A.py b/Mahendra/task1A.py new file mode 100644 index 0000000..a7b8f7a --- /dev/null +++ b/Mahendra/task1A.py @@ -0,0 +1,9 @@ +import numpy as np +n=100 +ycap=np.random.rand(n) +y=np.random.randint(0,2,n) +def cross_entropy_loss(y,ycap): + O = -np.sum((np.multiply(y,np.log2(ycap))+np.multiply(1-y,np.log2(1-ycap))))/n + return O + +print(cross_entropy_loss(y,ycap)) diff --git a/Mahendra/task1B.py b/Mahendra/task1B.py new file mode 100644 index 0000000..ffe80f6 --- /dev/null +++ b/Mahendra/task1B.py @@ -0,0 +1,16 @@ +class sumpairs: + def __init__(self, l, target): + self.l=l + self.target=target + self.d={} + + def findpairs(self): + for i in range(len(self.l)): + for j in range(len(self.l)): + if self.l[i]+self.l[j]==self.target: + self.d[len(self.d)+1]=[i,j] + return self.d + +#test: +a=sumpairs([10,20,10,40,50,60,70],50) +print(a.findpairs())