Skip to content
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
218 changes: 218 additions & 0 deletions Kishan_ED18B033/Python_and_Git_Basics_Assignment.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Python and Git Basics Assignment.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "zny-V2Xn4gaO"
},
"source": [
"import numpy as np"
],
"execution_count": 18,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "sqyrWGhL4tnS"
},
"source": [
"###Question 1"
]
},
{
"cell_type": "code",
"metadata": {
"id": "z2mggVkH48if"
},
"source": [
"n=100\n",
"y_hat=np.random.rand(n)\n",
"y=np.random.randint(2,size=n)"
],
"execution_count": 27,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "23yRC6R-m-7u",
"outputId": "a4fa5811-b3c7-4562-8929-f89ea49c326f"
},
"source": [
"y"
],
"execution_count": 20,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0,\n",
" 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0,\n",
" 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0,\n",
" 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1,\n",
" 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0])"
]
},
"metadata": {
"tags": []
},
"execution_count": 20
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "WraNkN-jnB0l",
"outputId": "3b0665a6-2753-417e-ac7d-4999709488c3"
},
"source": [
"y_hat"
],
"execution_count": 21,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([0.34864463, 0.16559192, 0.37362853, 0.34598581, 0.91034614,\n",
" 0.07371572, 0.97757352, 0.32367162, 0.03636325, 0.48169802,\n",
" 0.41836574, 0.0095018 , 0.39884979, 0.67443107, 0.14777916,\n",
" 0.7894044 , 0.5677986 , 0.99344523, 0.19177213, 0.90898506,\n",
" 0.33400728, 0.36978498, 0.49202978, 0.43397291, 0.46638816,\n",
" 0.76833813, 0.67366404, 0.45092255, 0.69703037, 0.15908994,\n",
" 0.30810762, 0.71688031, 0.20736601, 0.91189848, 0.58843871,\n",
" 0.94224774, 0.98938723, 0.84744487, 0.00234676, 0.27161741,\n",
" 0.314035 , 0.06726875, 0.90775704, 0.37697168, 0.55984568,\n",
" 0.58281242, 0.30790159, 0.97404284, 0.58008374, 0.51594752,\n",
" 0.06800683, 0.52346961, 0.35521804, 0.51587424, 0.69179825,\n",
" 0.14672081, 0.77049313, 0.59068372, 0.18585234, 0.2020049 ,\n",
" 0.94417364, 0.94238846, 0.9441901 , 0.32410688, 0.42514757,\n",
" 0.96141487, 0.56757249, 0.35028393, 0.22290532, 0.07660649,\n",
" 0.25634774, 0.30173228, 0.70496245, 0.18261014, 0.64850229,\n",
" 0.78946273, 0.79509855, 0.55768729, 0.38548223, 0.35092179,\n",
" 0.83009204, 0.9832498 , 0.12366334, 0.2062374 , 0.05886718,\n",
" 0.47965825, 0.24881469, 0.90449568, 0.57533269, 0.27871294,\n",
" 0.70803543, 0.52753435, 0.46341132, 0.67019264, 0.58059924,\n",
" 0.74252476, 0.14396854, 0.09010478, 0.5032765 , 0.57300749])"
]
},
"metadata": {
"tags": []
},
"execution_count": 21
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "gWioihz06tw3",
"outputId": "b40bccac-fab5-4d4e-ff76-362ce9ea7e91"
},
"source": [
"A=-(y*np.log2(y_hat)+(1-y)*np.log2(1-y_hat))/n\n",
"O=np.sum(A)\n",
"O"
],
"execution_count": 30,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"1.4752965067943884"
]
},
"metadata": {
"tags": []
},
"execution_count": 30
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gHzJterw8tBV"
},
"source": [
"###Question 2"
]
},
{
"cell_type": "code",
"metadata": {
"id": "fM5Ddei38vG9"
},
"source": [
"class Solution:\n",
" def __init__(self,arr,target):\n",
" self.arr=arr\n",
" self.target=target\n",
" def method(self):\n",
" sol={}\n",
" k=1\n",
" for i in range(len(self.arr)):\n",
" for j in range(len(self.arr)):\n",
" if self.arr[i]+self.arr[j]==self.target:\n",
" sol[k]=[i,j]\n",
" k+=1\n",
" print(sol)"
],
"execution_count": 8,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "T3PnvTzp-4TQ",
"outputId": "beb57d35-4392-4c6a-c445-ac5cd9e29239"
},
"source": [
"c1=Solution(arr=[4,10,6,14,18,19,20],target=20)\n",
"c1.method()"
],
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"text": [
"{0: [1, 1], 1: [2, 3], 2: [3, 2]}\n"
],
"name": "stdout"
}
]
}
]
}