diff --git a/Files/Task01A.py b/Files/Task01A.py new file mode 100644 index 0000000..0fc796d --- /dev/null +++ b/Files/Task01A.py @@ -0,0 +1,10 @@ +import numpy as np +import math +vec1 = np.random.rand(100) +vec2 = np.random.randint(0,2,100) +n = 100 +sum = 0 +for i in range(100): + sum = sum + (vec2[i] * math.log(vec1[i],2) + (1 - vec2[i]) * math.log(1 - vec1[i],2)) + +print(-sum/n) diff --git a/Files/Task01B.py b/Files/Task01B.py new file mode 100644 index 0000000..5efb362 --- /dev/null +++ b/Files/Task01B.py @@ -0,0 +1,19 @@ +import numpy as np +class target: + def __init__(self,arr,tgtsum): + self.arr = arr + self.tgtsum = tgtsum + self.dict = {} + self.c = 1 + def pairs(self): + for i in range(len(self.arr)): + for j in range(len(self.arr)): + if self.arr[i] + self.arr[j] == self.tgtsum: + self.dict[self.c] = [i,j] + self.c += 1 + + print(self.dict) +list = np.random.randint(0,100,25) +print(list) +s = target(list,50) +s.pairs()