Skip to content
Open
Show file tree
Hide file tree
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
100 changes: 100 additions & 0 deletions Suriyavelu_EE20B133_Q1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Suriyavelu_EE20B133_Q1.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "SDFKTeNHWLZa",
"outputId": "da9e76cb-e9bf-4d9d-a9e7-44f193784721"
},
"source": [
"import numpy as np\n",
"import math\n",
"\n",
"n=100\n",
"\n",
"\n",
"y = np.random.randint(0,2,n) \n",
"y_cap = np.random.rand(n) \n",
"print(y)\n",
"print(y_cap)\n"
],
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": [
"[0 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 0 0 1 0 0 0 1 1 1 1 0 0 1 1 1 1\n",
" 0 0 1 1 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0\n",
" 0 0 0 0 0 1 0 1 1 1 0 0 0 1 1 0 1 0 1 0 1 0 0 1 0 1]\n",
"[0.50843116 0.78699915 0.50202158 0.52106829 0.28161941 0.16601114\n",
" 0.9384779 0.30485966 0.39942285 0.90567719 0.03574462 0.5881971\n",
" 0.14019694 0.92671877 0.13934773 0.85074313 0.67121002 0.71395842\n",
" 0.33558059 0.5903323 0.31879301 0.06198635 0.24556822 0.07466601\n",
" 0.43721157 0.13593685 0.00992059 0.45817583 0.40927946 0.22564894\n",
" 0.1445847 0.10226209 0.64363656 0.42064902 0.35499586 0.58827634\n",
" 0.89216289 0.24871214 0.58451316 0.80645039 0.64237521 0.21490444\n",
" 0.50338188 0.93054383 0.51168319 0.54184681 0.86584254 0.12223733\n",
" 0.68539398 0.84773381 0.20668814 0.77859524 0.3267349 0.13798076\n",
" 0.86937541 0.81734972 0.88309045 0.36817757 0.39131509 0.54807128\n",
" 0.22312638 0.16619411 0.10839084 0.89327666 0.14085427 0.21007204\n",
" 0.78321333 0.70909767 0.99055622 0.44535312 0.3348796 0.079961\n",
" 0.62911996 0.16513801 0.52047628 0.65889891 0.4374228 0.84764263\n",
" 0.90535513 0.13666385 0.27738929 0.18072991 0.61858209 0.03406597\n",
" 0.06187498 0.6639932 0.50643604 0.22356646 0.06619615 0.69159683\n",
" 0.60229281 0.93616167 0.77759024 0.71181934 0.75295573 0.46097798\n",
" 0.72359395 0.02581449 0.35704973 0.34535144]\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "fb2XM5swW6KL",
"outputId": "b799b5d7-8e35-40d1-f020-719fb065dd93"
},
"source": [
"sum=0\n",
"\n",
"for i in range(n):\n",
" sum = sum + y[i]*math.log2(y_cap[i]) + (1-y[i])*math.log2(1-y_cap[i])\n",
"\n",
"Cross_Ent = (-1/n)*sum\n",
"\n",
"print(Cross_Ent)"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"1.3852640255804824\n"
],
"name": "stdout"
}
]
}
]
}
103 changes: 103 additions & 0 deletions Suriyavelu_EE20B133_Q2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Suriyavelu_EE20B133_Q2.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "xRR9cFX0XVRr",
"outputId": "3758de43-d55a-42cd-fa2a-a06e1dee0f6b"
},
"source": [
"class AddandCompare:\n",
"\n",
" dummy = 'A' \n",
"\n",
" def __init__(self,inarr,target):\n",
"\n",
" self.inarr = inarr \n",
" self.target = target \n",
" def show(self): \n",
" \n",
" print('imput array: ', self.inarr)\n",
" print('target: ', self.target)\n",
" print('dummy: ', self.dummy)\n",
"\n",
" def final(self): \n",
"\n",
" count = 1\n",
" output = {}\n",
"\n",
" for i in range(len(self.inarr)):\n",
" for j in range(len(self.inarr)):\n",
"\n",
" if(self.inarr[i]+self.inarr[j] == self.target and i!=j):\n",
" output[count] = list([i,j])\n",
" count = count + 1\n",
" return output\n",
"\n",
"Arr1 = []\n",
"Target = 0\n",
"m = 0\n",
"\n",
"print(\"Enter the target\")\n",
"Target = int(input())\n",
"\n",
"print(\"Enter the number of entries\")\n",
"m = int(input())\n",
"\n",
"print(\"Enter the elements\")\n",
"for i in range(m):\n",
" element = int(input())\n",
" Arr1.append(element)\n",
"\n",
"\n",
"Obj1 = AddandCompare(Arr1,Target) #Creating class instance\n",
"Obj1.show()\n",
"print(Obj1.final()) #Printing the output1"
],
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"text": [
"Enter the target\n",
"38\n",
"Enter the number of entries\n",
"8\n",
"Enter the elements\n",
"16\n",
"17\n",
"26\n",
"28\n",
"31\n",
"38\n",
"43\n",
"47\n",
"imput array: [16, 17, 26, 28, 31, 38, 43, 47]\n",
"target: 38\n",
"dummy: A\n",
"{}\n"
],
"name": "stdout"
}
]
}
]
}