Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prithvi #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Prithvi_P_Rao_EE22B024_DC_Task1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyMLcDPdQneH3rGT8VWeHfqj"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","source":["import numpy as np"],"metadata":{"id":"Mu7TyocHoThD"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":57,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"r_f4JOmhj2Ko","executionInfo":{"status":"ok","timestamp":1672636376615,"user_tz":-330,"elapsed":6,"user":{"displayName":"Prithvi Rao","userId":"12291986275579615423"}},"outputId":"8dffed0f-a77e-4e24-9502-0f3a362e7b0f"},"outputs":[{"output_type":"stream","name":"stdout","text":["-0.27291027324515854\n"]}],"source":["# Task A\n","y , yCap = np.random.randint(0,2,100) , np.random.rand(100) # Initialising the 2 arrays\n","res = y*np.log2(yCap) - (1-y)*(np.log2(1-yCap)) # computing value of each term of the expression\n","print(-np.average(res)) # printing out the Cross-Entropy loss value"]},{"cell_type":"code","source":["# Task B\n","class SumSearch():\n"," solutions = {}\n"," solCount = 0\n"," def __init__(self,numbers,target):\n"," self.numbers = numbers\n"," self.target = target\n"," def Compute(self):\n"," for i in range(len(numbers)): # parsing through each element in the given array\n"," for j in range(i,len(numbers)): # parsing through the elements which are not behind numbers[i]\n"," if (numbers[i]+numbers[j] == target): # checking the condition\n"," self.solCount += 1\n"," self.solutions[self.solCount] = [i,j] #appending the pair of indices to the list of solutions\n"," if(i != j): #checking if the indices are not equal\n"," self.solCount += 1\n"," self.solutions[self.solCount] = [j,i] # adding the reversed pair of indices to the solution \n"," print(self.solutions)\n","\n","numbers = [10,20,10,40,50,60,70]\n","target = 50\n","C1 = SumSearch(numbers,target) # creatitng the class\n","C1.Compute() # calling the function"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"b_gStVYdoyeV","executionInfo":{"status":"ok","timestamp":1672633055474,"user_tz":-330,"elapsed":5,"user":{"displayName":"Prithvi Rao","userId":"12291986275579615423"}},"outputId":"d9bdaa35-86a2-40f0-fd0b-c81f9b19b9a3"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["{1: [0, 3], 2: [3, 0], 3: [2, 3], 4: [3, 2]}\n"]}]}]}