├── CODE_OF_CONDUCT.md
├── README.md
├── coding_prac
├── .ipynb_checkpoints
│ ├── coding_prac-checkpoint.ipynb
│ ├── day 21-checkpoint.ipynb
│ └── day22-checkpoint.ipynb
├── coding_prac.ipynb
├── day 21.ipynb
└── day22.ipynb
├── lists
├── Day 2.ipynb
├── Day1.ipynb
└── day19.ipynb
├── numpy
├── Day 6.ipynb
├── Day3.ipynb
├── Day4.ipynb
├── Day5.ipynb
├── Day7.ipynb
├── Day8.ipynb
└── archive.ics.uci.edu
│ └── ml
│ └── machine-learning-databases
│ └── iris
│ └── iris.data
├── output_based_questions
├── Day11.ipynb
├── Day15.ipynb
├── day10.ipynb
├── day12.ipynb
├── day13.ipynb
├── day14.ipynb
├── day16.ipynb
├── day9.ipynb
└── images
│ ├── day10_1.png
│ ├── day10_2.png
│ ├── day10_3.png
│ ├── day10_4.png
│ ├── day11_1.png
│ ├── day11_2.png
│ ├── day11_3.png
│ ├── day11_4.png
│ ├── day12.png
│ ├── day12_2.png
│ ├── day12_3.png
│ ├── day13_1.PNG
│ ├── day13_2.PNG
│ ├── day13_3.PNG
│ ├── day14_1.png
│ ├── day14_10.png
│ ├── day14_2.png
│ ├── day14_3.png
│ ├── day14_4.png
│ ├── day14_5.png
│ ├── day14_6.png
│ ├── day14_7.png
│ ├── day14_8.png
│ ├── day14_9.png
│ ├── day15_1.png
│ ├── day15_2.png
│ ├── day15_3.png
│ ├── day15_4.png
│ ├── day15_5.png
│ ├── day15_6.png
│ ├── day16_1.png
│ ├── day16_2.png
│ ├── day16_3.png
│ ├── day16_4.png
│ ├── day16_5.png
│ ├── day16_6.png
│ ├── day16_7.png
│ ├── day9_1.png
│ ├── day9_2.png
│ ├── day9_3.png
│ ├── day9_4.png
│ └── day9_5.png
└── pandas
├── Automobile_data.csv
├── day17.ipynb
├── day18.ipynb
└── images
├── day17_1.PNG
├── day17_10.PNG
├── day17_2.PNG
├── day17_3.PNG
├── day17_4.PNG
├── day17_5.PNG
├── day17_6.PNG
├── day17_7.PNG
├── day17_8.PNG
├── day17_9.PNG
├── day18_1.png
├── day18_2.png
├── day18_3.png
└── day18_4.png
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at samshashcool@gmail.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Udaquest :smiley:
2 |
3 | This repository is an active initiative thanks to #60daysofudacity
4 |
5 | This Repository deals with solving and acessing Machine learning and some Python related problems.
6 |
7 | **What We Will be Doing?**
8 |
9 | [Aisha](https://github.com/aishajv) will be Posting some questions related to machine learning every day on slack.
10 |
11 | I will be acessing those answers given by the community and those with the most relevant answers will be posted on the github or interested guys can make a pull request to this repository I after reviewing that pull request will merge that with the repository
12 |
13 | **Further Initiatives**
14 |
15 | Deciding to increase the community involved while working with some opensource projects and some udacity related project tasks.
16 |
17 | **Let's Code** :smiley::smiley:
18 |
19 |
--------------------------------------------------------------------------------
/coding_prac/.ipynb_checkpoints/coding_prac-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "\n",
8 | "\n",
9 | "### Question 1.\n",
10 | "\n",
11 | "Given an unsorted array A of size N of non-negative integers, find a continuous sub-array which adds to a given number S.\n",
12 | "\n",
13 | "#### Input:\n",
14 | "\n",
15 | "The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case \n",
16 | "\n",
17 | "consists of two lines. The first line of each test case is N and S, where N is the size of array and S is the sum. The \n",
18 | "\n",
19 | "second line of each test case contains N space separated integers denoting the array elements.\n",
20 | "\n",
21 | "\n",
22 | "#### Output:\n",
23 | "\n",
24 | "For each testcase, in a new line, print the starting and ending positions(1 indexing) of first such occuring subarray \n",
25 | "\n",
26 | "from the left if sum equals to subarray, else print -1.\n",
27 | "\n",
28 | "#### Constraints:\n",
29 | "\n",
30 | "1 <= T <= 100\n",
31 | "\n",
32 | "1 <= N <= 107\n",
33 | "\n",
34 | "1 <= Ai <= 1010\n",
35 | "\n",
36 | "\n",
37 | "#### Example:\n",
38 | "\n",
39 | "#### Input:\n",
40 | "\n",
41 | "2\n",
42 | "\n",
43 | "5 12\n",
44 | "\n",
45 | "1 2 3 7 5\n",
46 | "\n",
47 | "10 15\n",
48 | "\n",
49 | "1 2 3 4 5 6 7 8 9 10\n",
50 | "\n",
51 | "#### Output:\n",
52 | "\n",
53 | "2 4\n",
54 | "\n",
55 | "1 5\n",
56 | "\n",
57 | "\n",
58 | "Explanation :\n",
59 | "\n",
60 | "Testcase1: sum of elements from 2nd position to 4th position is 12\n",
61 | "\n",
62 | "Testcase2: sum of elements from 1st position to 5th position is 15\n",
63 | "\n",
64 | "** For More Input/Output Examples Use 'Expected Output' option **\n"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": 27,
70 | "metadata": {},
71 | "outputs": [
72 | {
73 | "name": "stdout",
74 | "output_type": "stream",
75 | "text": [
76 | "2\n"
77 | ]
78 | }
79 | ],
80 | "source": [
81 | "test_cases=int(input())"
82 | ]
83 | },
84 | {
85 | "cell_type": "code",
86 | "execution_count": 28,
87 | "metadata": {},
88 | "outputs": [
89 | {
90 | "name": "stdout",
91 | "output_type": "stream",
92 | "text": [
93 | "5 12\n",
94 | "1 2 3 7 5\n",
95 | "10 15\n",
96 | "1 2 3 4 5 6 7 8 9 10\n"
97 | ]
98 | }
99 | ],
100 | "source": [
101 | "c=[]\n",
102 | "d=[]\n",
103 | "for i in range(0,test_cases):\n",
104 | " n,sum1=list(map(int,input().split()))\n",
105 | " b=list(map(int,input().split()))\n",
106 | " sum2=0\n",
107 | " for idx,j in enumerate(b):\n",
108 | " for k in range(idx,len(b)): \n",
109 | " sm1=sum(b[idx:len(b)-k])\n",
110 | " flag=0\n",
111 | " if sum1==sm1:\n",
112 | " d.append(idx+1)\n",
113 | " c.append(len(b)-k)\n",
114 | " flag=1\n",
115 | " if flag==1:\n",
116 | " break"
117 | ]
118 | },
119 | {
120 | "cell_type": "code",
121 | "execution_count": 32,
122 | "metadata": {},
123 | "outputs": [
124 | {
125 | "name": "stdout",
126 | "output_type": "stream",
127 | "text": [
128 | "2 4\n",
129 | "1 5\n"
130 | ]
131 | }
132 | ],
133 | "source": [
134 | "print(d[0],c[0])\n",
135 | "print(d[1],c[1])"
136 | ]
137 | },
138 | {
139 | "cell_type": "markdown",
140 | "metadata": {},
141 | "source": [
142 | "### Question 2 Max Index\n",
143 | "\n",
144 | "Given an array A[] of N positive integers. The task is to find the maximum of j - i subjected to the constraint of A[i] <= A[j].\n",
145 | "\n",
146 | "#### Input:\n",
147 | "The first line contains an integer T, depicting total number of test cases. Then T test case follows. First line of each test case contains an integer N denoting the size of the array. Next line contains N space separated integeres denoting the elements of the array.\n",
148 | "\n",
149 | "#### Output:\n",
150 | "Print the maximum difference of the indexes i and j in a separtate line.\n",
151 | "\n",
152 | "#### Constraints:\n",
153 | "1 ≤ T ≤ 1000\n",
154 | "\n",
155 | "1 ≤ N ≤ 107\n",
156 | "\n",
157 | "0 ≤ A[i] ≤ 1018\n",
158 | "\n",
159 | "#### Example:\n",
160 | "#### Input:\n",
161 | "1\n",
162 | "\n",
163 | "9\n",
164 | "\n",
165 | "34 8 10 3 2 80 30 33 1\n",
166 | "\n",
167 | "#### Output:\n",
168 | "\n",
169 | "6\n",
170 | "\n",
171 | "#### Explanation:\n",
172 | "Testcase 1: In the given array A[1] < A[7] satisfying the required condition(A[i] <= A[j]) thus giving the maximum difference of j - i which is 6(7-1)."
173 | ]
174 | },
175 | {
176 | "cell_type": "code",
177 | "execution_count": 33,
178 | "metadata": {},
179 | "outputs": [
180 | {
181 | "name": "stdout",
182 | "output_type": "stream",
183 | "text": [
184 | "1\n"
185 | ]
186 | }
187 | ],
188 | "source": [
189 | "test_cases=int(input())"
190 | ]
191 | },
192 | {
193 | "cell_type": "code",
194 | "execution_count": 34,
195 | "metadata": {},
196 | "outputs": [
197 | {
198 | "name": "stdout",
199 | "output_type": "stream",
200 | "text": [
201 | "9\n"
202 | ]
203 | }
204 | ],
205 | "source": [
206 | "n=int(input())"
207 | ]
208 | },
209 | {
210 | "cell_type": "code",
211 | "execution_count": 35,
212 | "metadata": {},
213 | "outputs": [
214 | {
215 | "name": "stdout",
216 | "output_type": "stream",
217 | "text": [
218 | "34 8 10 3 2 80 30 33 1\n"
219 | ]
220 | }
221 | ],
222 | "source": [
223 | "c=list(map(int,input().split()))"
224 | ]
225 | },
226 | {
227 | "cell_type": "code",
228 | "execution_count": 36,
229 | "metadata": {},
230 | "outputs": [
231 | {
232 | "data": {
233 | "text/plain": [
234 | "[34, 8, 10, 3, 2, 80, 30, 33, 1]"
235 | ]
236 | },
237 | "execution_count": 36,
238 | "metadata": {},
239 | "output_type": "execute_result"
240 | }
241 | ],
242 | "source": [
243 | "c"
244 | ]
245 | },
246 | {
247 | "cell_type": "code",
248 | "execution_count": 37,
249 | "metadata": {
250 | "collapsed": true
251 | },
252 | "outputs": [],
253 | "source": [
254 | "a=0\n",
255 | "for idx,i in enumerate(c):\n",
256 | " for j in range(idx+1,len(c)):\n",
257 | " if c[idx]<=j:\n",
258 | " b=j-c[idx]\n",
259 | " if aQuestions\n",
8 | "\n",
9 | "Sum of bit differences among all pairs
\n",
10 | "\n",
11 | "Given an integer array of n integers, find sum of bit differences in all pairs that can be formed from array elements.\n",
12 | "\n",
13 | "Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y.\n",
14 | "\n",
15 | "For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 is 111 ( first and last bits differ in two numbers).\n",
16 | "\n",
17 | "Examples :\n",
18 | "\n",
19 | " Input: arr[] = {1, 2}\n",
20 | "\n",
21 | "Output: 4\n",
22 | "\n",
23 | "All pairs in array are (1, 1), (1, 2)\n",
24 | " (2, 1), (2, 2)\n",
25 | "\n",
26 | "Sum of bit differences = 0 + 2 +2 + 0\n",
27 | " = 4\n",
28 | "\n",
29 | "Input: arr[] = {1, 3, 5}\n",
30 | "\n",
31 | "Output: 8\n",
32 | "\n",
33 | "All pairs in array are (1, 1), (1, 3), (1, 5)\n",
34 | " (3, 1), (3, 3) (3, 5),\n",
35 | " (5, 1), (5, 3), (5, 5)\n",
36 | "\n",
37 | "Sum of bit differences = 0 + 1 + 1 +\n",
38 | " 1 + 0 + 2 +\n",
39 | " 1 + 2 + 0 \n",
40 | " = 8 \n"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": 87,
46 | "metadata": {},
47 | "outputs": [
48 | {
49 | "name": "stdout",
50 | "output_type": "stream",
51 | "text": [
52 | "3,4\n"
53 | ]
54 | }
55 | ],
56 | "source": [
57 | "a=list(map(int,input().split(\",\")))"
58 | ]
59 | },
60 | {
61 | "cell_type": "code",
62 | "execution_count": 88,
63 | "metadata": {
64 | "scrolled": true
65 | },
66 | "outputs": [],
67 | "source": [
68 | "import itertools\n",
69 | "b=[]\n",
70 | "for i in range(0,len(a)+1):\n",
71 | " for j in itertools.permutations(a,i):\n",
72 | " if len(j)>=1:\n",
73 | " b.append(j)"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": 89,
79 | "metadata": {},
80 | "outputs": [],
81 | "source": [
82 | "sum=0\n",
83 | "for i in b:\n",
84 | " if len(i)>1:\n",
85 | " c,d=i\n",
86 | " c=str(bin(c))[2:]\n",
87 | " d=str(bin(d))[2:]\n",
88 | " if len(c)>len(d):\n",
89 | " d=\"0\"+d\n",
90 | " for j in range(0,len(d)):\n",
91 | " if c[j]!=d[j]:\n",
92 | " sum+=1\n",
93 | " else:\n",
94 | " c=\"0\"+c\n",
95 | " for j in range(0,len(c)):\n",
96 | " if c[j]!=d[j]:\n",
97 | " sum+=1"
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": 90,
103 | "metadata": {},
104 | "outputs": [
105 | {
106 | "data": {
107 | "text/plain": [
108 | "6"
109 | ]
110 | },
111 | "execution_count": 90,
112 | "metadata": {},
113 | "output_type": "execute_result"
114 | }
115 | ],
116 | "source": [
117 | "sum"
118 | ]
119 | },
120 | {
121 | "cell_type": "markdown",
122 | "metadata": {},
123 | "source": [
124 | "\n",
125 | "Inplace rotate square matrix by 90 degrees | Set 1\n",
126 | "\n",
127 | "Given an square matrix, turn it by 90 degrees in anti-clockwise direction without using any extra space.\n",
128 | "\n",
129 | "##### Examples :\n",
130 | "\n",
131 | "#### Input\n",
132 | "\n",
133 | " 1 2 3\n",
134 | "\n",
135 | " 4 5 6\n",
136 | " \n",
137 | " 7 8 9\n",
138 | "\n",
139 | "##### Output:\n",
140 | " \n",
141 | " 3 6 9 \n",
142 | " \n",
143 | " 2 5 8 \n",
144 | " \n",
145 | " 1 4 7 \n",
146 | "\n",
147 | "##### Input:\n",
148 | " \n",
149 | " 1 2 3 4 \n",
150 | " \n",
151 | " 5 6 7 8 \n",
152 | " \n",
153 | " 9 10 11 12 \n",
154 | "\n",
155 | " 13 14 15 16 \n",
156 | "\n",
157 | "##### Output:\n",
158 | "\n",
159 | " 4 8 12 16 \n",
160 | "\n",
161 | " 3 7 11 15 \n",
162 | " \n",
163 | " 2 6 10 14 \n",
164 | " \n",
165 | " 1 5 9 13"
166 | ]
167 | },
168 | {
169 | "cell_type": "code",
170 | "execution_count": 91,
171 | "metadata": {},
172 | "outputs": [
173 | {
174 | "name": "stdout",
175 | "output_type": "stream",
176 | "text": [
177 | "4 8 12 16 \n",
178 | "3 7 11 15 \n",
179 | "2 6 10 14 \n",
180 | "1 5 9 13 \n"
181 | ]
182 | }
183 | ],
184 | "source": [
185 | "# Python3 program to rotate a matrix by 90 degrees \n",
186 | "N = 4\n",
187 | " \n",
188 | "# An Inplace function to rotate \n",
189 | "# N x N matrix by 90 degrees in \n",
190 | "# anti-clockwise direction \n",
191 | "def rotateMatrix(mat): \n",
192 | " \n",
193 | " # Consider all squares one by one \n",
194 | " for x in range(0, int(N/2)): \n",
195 | " \n",
196 | " # Consider elements in group \n",
197 | " # of 4 in current square \n",
198 | " for y in range(x, N-x-1): \n",
199 | " \n",
200 | " # store current cell in temp variable \n",
201 | " temp = mat[x][y] \n",
202 | " \n",
203 | " # move values from right to top \n",
204 | " mat[x][y] = mat[y][N-1-x] \n",
205 | " \n",
206 | " # move values from bottom to right \n",
207 | " mat[y][N-1-x] = mat[N-1-x][N-1-y] \n",
208 | " \n",
209 | " # move values from left to bottom \n",
210 | " mat[N-1-x][N-1-y] = mat[N-1-y][x] \n",
211 | " \n",
212 | " # assign temp to left \n",
213 | " mat[N-1-y][x] = temp \n",
214 | " \n",
215 | " \n",
216 | "# Function to pr the matrix \n",
217 | "def displayMatrix( mat ): \n",
218 | " \n",
219 | " for i in range(0, N): \n",
220 | " \n",
221 | " for j in range(0, N): \n",
222 | " \n",
223 | " print (mat[i][j], end = ' ') \n",
224 | " print (\"\") \n",
225 | " \n",
226 | " \n",
227 | " \n",
228 | " \n",
229 | "# Driver Code \n",
230 | "mat = [[0 for x in range(N)] for y in range(N)] \n",
231 | " \n",
232 | "# Test case 1 \n",
233 | "mat = [ [1, 2, 3, 4 ], \n",
234 | " [5, 6, 7, 8 ], \n",
235 | " [9, 10, 11, 12 ], \n",
236 | " [13, 14, 15, 16 ] ] \n",
237 | " \n",
238 | "''' \n",
239 | "# Test case 2 \n",
240 | "mat = [ [1, 2, 3 ], \n",
241 | " [4, 5, 6 ], \n",
242 | " [7, 8, 9 ] ] \n",
243 | " \n",
244 | "# Test case 3 \n",
245 | "mat = [ [1, 2 ], \n",
246 | " [4, 5 ] ] \n",
247 | " \n",
248 | "'''\n",
249 | " \n",
250 | "rotateMatrix(mat) \n",
251 | " \n",
252 | "# Print rotated matrix \n",
253 | "displayMatrix(mat) "
254 | ]
255 | },
256 | {
257 | "cell_type": "code",
258 | "execution_count": null,
259 | "metadata": {
260 | "collapsed": true
261 | },
262 | "outputs": [],
263 | "source": []
264 | }
265 | ],
266 | "metadata": {
267 | "kernelspec": {
268 | "display_name": "Python 3",
269 | "language": "python",
270 | "name": "python3"
271 | },
272 | "language_info": {
273 | "codemirror_mode": {
274 | "name": "ipython",
275 | "version": 3
276 | },
277 | "file_extension": ".py",
278 | "mimetype": "text/x-python",
279 | "name": "python",
280 | "nbconvert_exporter": "python",
281 | "pygments_lexer": "ipython3",
282 | "version": "3.6.8"
283 | }
284 | },
285 | "nbformat": 4,
286 | "nbformat_minor": 2
287 | }
288 |
--------------------------------------------------------------------------------
/coding_prac/.ipynb_checkpoints/day22-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | " Questions
\n",
8 | "\n",
9 | "##### Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.\n",
10 | "\n",
11 | "##### Example 1:\n",
12 | "\n",
13 | "##### Input: 121\n",
14 | "\n",
15 | "##### Output: true\n",
16 | "\n",
17 | "##### Example 2:\n",
18 | "\n",
19 | "##### Input: -121\n",
20 | "\n",
21 | "##### Output: False\n",
22 | "\n",
23 | "##### Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.\n",
24 | "\n",
25 | "##### Example 3:\n",
26 | "\n",
27 | "##### Input: 10\n",
28 | "\n",
29 | "##### Output: false\n",
30 | "\n",
31 | "##### Explanation: Reads 01 from right to left. Therefore it is not a palindrome.\n"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": 4,
37 | "metadata": {},
38 | "outputs": [
39 | {
40 | "name": "stdout",
41 | "output_type": "stream",
42 | "text": [
43 | "False\n"
44 | ]
45 | }
46 | ],
47 | "source": [
48 | "class Solution:\n",
49 | " def isPalindrome(self, x: int) -> bool:\n",
50 | " a=str(x)\n",
51 | " if a[:]==a[::-1]:\n",
52 | " return True\n",
53 | " else:\n",
54 | " return False\n",
55 | "\n",
56 | "sol=Solution()\n",
57 | "a=sol.isPalindrome(-121)\n",
58 | "print(a)\n",
59 | " "
60 | ]
61 | },
62 | {
63 | "cell_type": "code",
64 | "execution_count": null,
65 | "metadata": {
66 | "collapsed": true
67 | },
68 | "outputs": [],
69 | "source": []
70 | }
71 | ],
72 | "metadata": {
73 | "kernelspec": {
74 | "display_name": "Python 3",
75 | "language": "python",
76 | "name": "python3"
77 | },
78 | "language_info": {
79 | "codemirror_mode": {
80 | "name": "ipython",
81 | "version": 3
82 | },
83 | "file_extension": ".py",
84 | "mimetype": "text/x-python",
85 | "name": "python",
86 | "nbconvert_exporter": "python",
87 | "pygments_lexer": "ipython3",
88 | "version": "3.6.8"
89 | }
90 | },
91 | "nbformat": 4,
92 | "nbformat_minor": 2
93 | }
94 |
--------------------------------------------------------------------------------
/coding_prac/coding_prac.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "\n",
8 | "\n",
9 | "### Question 1.\n",
10 | "\n",
11 | "Given an unsorted array A of size N of non-negative integers, find a continuous sub-array which adds to a given number S.\n",
12 | "\n",
13 | "#### Input:\n",
14 | "\n",
15 | "The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case \n",
16 | "\n",
17 | "consists of two lines. The first line of each test case is N and S, where N is the size of array and S is the sum. The \n",
18 | "\n",
19 | "second line of each test case contains N space separated integers denoting the array elements.\n",
20 | "\n",
21 | "\n",
22 | "#### Output:\n",
23 | "\n",
24 | "For each testcase, in a new line, print the starting and ending positions(1 indexing) of first such occuring subarray \n",
25 | "\n",
26 | "from the left if sum equals to subarray, else print -1.\n",
27 | "\n",
28 | "#### Constraints:\n",
29 | "\n",
30 | "1 <= T <= 100\n",
31 | "\n",
32 | "1 <= N <= 107\n",
33 | "\n",
34 | "1 <= Ai <= 1010\n",
35 | "\n",
36 | "\n",
37 | "#### Example:\n",
38 | "\n",
39 | "#### Input:\n",
40 | "\n",
41 | "2\n",
42 | "\n",
43 | "5 12\n",
44 | "\n",
45 | "1 2 3 7 5\n",
46 | "\n",
47 | "10 15\n",
48 | "\n",
49 | "1 2 3 4 5 6 7 8 9 10\n",
50 | "\n",
51 | "#### Output:\n",
52 | "\n",
53 | "2 4\n",
54 | "\n",
55 | "1 5\n",
56 | "\n",
57 | "\n",
58 | "Explanation :\n",
59 | "\n",
60 | "Testcase1: sum of elements from 2nd position to 4th position is 12\n",
61 | "\n",
62 | "Testcase2: sum of elements from 1st position to 5th position is 15\n",
63 | "\n",
64 | "** For More Input/Output Examples Use 'Expected Output' option **\n"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": 27,
70 | "metadata": {},
71 | "outputs": [
72 | {
73 | "name": "stdout",
74 | "output_type": "stream",
75 | "text": [
76 | "2\n"
77 | ]
78 | }
79 | ],
80 | "source": [
81 | "test_cases=int(input())"
82 | ]
83 | },
84 | {
85 | "cell_type": "code",
86 | "execution_count": 28,
87 | "metadata": {},
88 | "outputs": [
89 | {
90 | "name": "stdout",
91 | "output_type": "stream",
92 | "text": [
93 | "5 12\n",
94 | "1 2 3 7 5\n",
95 | "10 15\n",
96 | "1 2 3 4 5 6 7 8 9 10\n"
97 | ]
98 | }
99 | ],
100 | "source": [
101 | "c=[]\n",
102 | "d=[]\n",
103 | "for i in range(0,test_cases):\n",
104 | " n,sum1=list(map(int,input().split()))\n",
105 | " b=list(map(int,input().split()))\n",
106 | " sum2=0\n",
107 | " for idx,j in enumerate(b):\n",
108 | " for k in range(idx,len(b)): \n",
109 | " sm1=sum(b[idx:len(b)-k])\n",
110 | " flag=0\n",
111 | " if sum1==sm1:\n",
112 | " d.append(idx+1)\n",
113 | " c.append(len(b)-k)\n",
114 | " flag=1\n",
115 | " if flag==1:\n",
116 | " break"
117 | ]
118 | },
119 | {
120 | "cell_type": "code",
121 | "execution_count": 32,
122 | "metadata": {},
123 | "outputs": [
124 | {
125 | "name": "stdout",
126 | "output_type": "stream",
127 | "text": [
128 | "2 4\n",
129 | "1 5\n"
130 | ]
131 | }
132 | ],
133 | "source": [
134 | "print(d[0],c[0])\n",
135 | "print(d[1],c[1])"
136 | ]
137 | },
138 | {
139 | "cell_type": "markdown",
140 | "metadata": {},
141 | "source": [
142 | "### Question 2 Max Index\n",
143 | "\n",
144 | "Given an array A[] of N positive integers. The task is to find the maximum of j - i subjected to the constraint of A[i] <= A[j].\n",
145 | "\n",
146 | "#### Input:\n",
147 | "The first line contains an integer T, depicting total number of test cases. Then T test case follows. First line of each test case contains an integer N denoting the size of the array. Next line contains N space separated integeres denoting the elements of the array.\n",
148 | "\n",
149 | "#### Output:\n",
150 | "Print the maximum difference of the indexes i and j in a separtate line.\n",
151 | "\n",
152 | "#### Constraints:\n",
153 | "1 ≤ T ≤ 1000\n",
154 | "\n",
155 | "1 ≤ N ≤ 107\n",
156 | "\n",
157 | "0 ≤ A[i] ≤ 1018\n",
158 | "\n",
159 | "#### Example:\n",
160 | "#### Input:\n",
161 | "1\n",
162 | "\n",
163 | "9\n",
164 | "\n",
165 | "34 8 10 3 2 80 30 33 1\n",
166 | "\n",
167 | "#### Output:\n",
168 | "\n",
169 | "6\n",
170 | "\n",
171 | "#### Explanation:\n",
172 | "Testcase 1: In the given array A[1] < A[7] satisfying the required condition(A[i] <= A[j]) thus giving the maximum difference of j - i which is 6(7-1)."
173 | ]
174 | },
175 | {
176 | "cell_type": "code",
177 | "execution_count": 33,
178 | "metadata": {},
179 | "outputs": [
180 | {
181 | "name": "stdout",
182 | "output_type": "stream",
183 | "text": [
184 | "1\n"
185 | ]
186 | }
187 | ],
188 | "source": [
189 | "test_cases=int(input())"
190 | ]
191 | },
192 | {
193 | "cell_type": "code",
194 | "execution_count": 34,
195 | "metadata": {},
196 | "outputs": [
197 | {
198 | "name": "stdout",
199 | "output_type": "stream",
200 | "text": [
201 | "9\n"
202 | ]
203 | }
204 | ],
205 | "source": [
206 | "n=int(input())"
207 | ]
208 | },
209 | {
210 | "cell_type": "code",
211 | "execution_count": 35,
212 | "metadata": {},
213 | "outputs": [
214 | {
215 | "name": "stdout",
216 | "output_type": "stream",
217 | "text": [
218 | "34 8 10 3 2 80 30 33 1\n"
219 | ]
220 | }
221 | ],
222 | "source": [
223 | "c=list(map(int,input().split()))"
224 | ]
225 | },
226 | {
227 | "cell_type": "code",
228 | "execution_count": 36,
229 | "metadata": {},
230 | "outputs": [
231 | {
232 | "data": {
233 | "text/plain": [
234 | "[34, 8, 10, 3, 2, 80, 30, 33, 1]"
235 | ]
236 | },
237 | "execution_count": 36,
238 | "metadata": {},
239 | "output_type": "execute_result"
240 | }
241 | ],
242 | "source": [
243 | "c"
244 | ]
245 | },
246 | {
247 | "cell_type": "code",
248 | "execution_count": 37,
249 | "metadata": {
250 | "collapsed": true
251 | },
252 | "outputs": [],
253 | "source": [
254 | "a=0\n",
255 | "for idx,i in enumerate(c):\n",
256 | " for j in range(idx+1,len(c)):\n",
257 | " if c[idx]<=j:\n",
258 | " b=j-c[idx]\n",
259 | " if aQuestions\n",
8 | "\n",
9 | "Sum of bit differences among all pairs
\n",
10 | "\n",
11 | "Given an integer array of n integers, find sum of bit differences in all pairs that can be formed from array elements.\n",
12 | "\n",
13 | "Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y.\n",
14 | "\n",
15 | "For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 is 111 ( first and last bits differ in two numbers).\n",
16 | "\n",
17 | "Examples :\n",
18 | "\n",
19 | " Input: arr[] = {1, 2}\n",
20 | "\n",
21 | "Output: 4\n",
22 | "\n",
23 | "All pairs in array are (1, 1), (1, 2)\n",
24 | " (2, 1), (2, 2)\n",
25 | "\n",
26 | "Sum of bit differences = 0 + 2 +2 + 0\n",
27 | " = 4\n",
28 | "\n",
29 | "Input: arr[] = {1, 3, 5}\n",
30 | "\n",
31 | "Output: 8\n",
32 | "\n",
33 | "All pairs in array are (1, 1), (1, 3), (1, 5)\n",
34 | " (3, 1), (3, 3) (3, 5),\n",
35 | " (5, 1), (5, 3), (5, 5)\n",
36 | "\n",
37 | "Sum of bit differences = 0 + 1 + 1 +\n",
38 | " 1 + 0 + 2 +\n",
39 | " 1 + 2 + 0 \n",
40 | " = 8 \n"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": 87,
46 | "metadata": {},
47 | "outputs": [
48 | {
49 | "name": "stdout",
50 | "output_type": "stream",
51 | "text": [
52 | "3,4\n"
53 | ]
54 | }
55 | ],
56 | "source": [
57 | "a=list(map(int,input().split(\",\")))"
58 | ]
59 | },
60 | {
61 | "cell_type": "code",
62 | "execution_count": 88,
63 | "metadata": {
64 | "scrolled": true
65 | },
66 | "outputs": [],
67 | "source": [
68 | "import itertools\n",
69 | "b=[]\n",
70 | "for i in range(0,len(a)+1):\n",
71 | " for j in itertools.permutations(a,i):\n",
72 | " if len(j)>=1:\n",
73 | " b.append(j)"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": 89,
79 | "metadata": {},
80 | "outputs": [],
81 | "source": [
82 | "sum=0\n",
83 | "for i in b:\n",
84 | " if len(i)>1:\n",
85 | " c,d=i\n",
86 | " c=str(bin(c))[2:]\n",
87 | " d=str(bin(d))[2:]\n",
88 | " if len(c)>len(d):\n",
89 | " d=\"0\"+d\n",
90 | " for j in range(0,len(d)):\n",
91 | " if c[j]!=d[j]:\n",
92 | " sum+=1\n",
93 | " else:\n",
94 | " c=\"0\"+c\n",
95 | " for j in range(0,len(c)):\n",
96 | " if c[j]!=d[j]:\n",
97 | " sum+=1"
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": 90,
103 | "metadata": {},
104 | "outputs": [
105 | {
106 | "data": {
107 | "text/plain": [
108 | "6"
109 | ]
110 | },
111 | "execution_count": 90,
112 | "metadata": {},
113 | "output_type": "execute_result"
114 | }
115 | ],
116 | "source": [
117 | "sum"
118 | ]
119 | },
120 | {
121 | "cell_type": "markdown",
122 | "metadata": {},
123 | "source": [
124 | "\n",
125 | "Inplace rotate square matrix by 90 degrees | Set 1\n",
126 | "\n",
127 | "Given an square matrix, turn it by 90 degrees in anti-clockwise direction without using any extra space.\n",
128 | "\n",
129 | "##### Examples :\n",
130 | "\n",
131 | "#### Input\n",
132 | "\n",
133 | " 1 2 3\n",
134 | "\n",
135 | " 4 5 6\n",
136 | " \n",
137 | " 7 8 9\n",
138 | "\n",
139 | "##### Output:\n",
140 | " \n",
141 | " 3 6 9 \n",
142 | " \n",
143 | " 2 5 8 \n",
144 | " \n",
145 | " 1 4 7 \n",
146 | "\n",
147 | "##### Input:\n",
148 | " \n",
149 | " 1 2 3 4 \n",
150 | " \n",
151 | " 5 6 7 8 \n",
152 | " \n",
153 | " 9 10 11 12 \n",
154 | "\n",
155 | " 13 14 15 16 \n",
156 | "\n",
157 | "##### Output:\n",
158 | "\n",
159 | " 4 8 12 16 \n",
160 | "\n",
161 | " 3 7 11 15 \n",
162 | " \n",
163 | " 2 6 10 14 \n",
164 | " \n",
165 | " 1 5 9 13"
166 | ]
167 | },
168 | {
169 | "cell_type": "code",
170 | "execution_count": 91,
171 | "metadata": {},
172 | "outputs": [
173 | {
174 | "name": "stdout",
175 | "output_type": "stream",
176 | "text": [
177 | "4 8 12 16 \n",
178 | "3 7 11 15 \n",
179 | "2 6 10 14 \n",
180 | "1 5 9 13 \n"
181 | ]
182 | }
183 | ],
184 | "source": [
185 | "# Python3 program to rotate a matrix by 90 degrees \n",
186 | "N = 4\n",
187 | " \n",
188 | "# An Inplace function to rotate \n",
189 | "# N x N matrix by 90 degrees in \n",
190 | "# anti-clockwise direction \n",
191 | "def rotateMatrix(mat): \n",
192 | " \n",
193 | " # Consider all squares one by one \n",
194 | " for x in range(0, int(N/2)): \n",
195 | " \n",
196 | " # Consider elements in group \n",
197 | " # of 4 in current square \n",
198 | " for y in range(x, N-x-1): \n",
199 | " \n",
200 | " # store current cell in temp variable \n",
201 | " temp = mat[x][y] \n",
202 | " \n",
203 | " # move values from right to top \n",
204 | " mat[x][y] = mat[y][N-1-x] \n",
205 | " \n",
206 | " # move values from bottom to right \n",
207 | " mat[y][N-1-x] = mat[N-1-x][N-1-y] \n",
208 | " \n",
209 | " # move values from left to bottom \n",
210 | " mat[N-1-x][N-1-y] = mat[N-1-y][x] \n",
211 | " \n",
212 | " # assign temp to left \n",
213 | " mat[N-1-y][x] = temp \n",
214 | " \n",
215 | " \n",
216 | "# Function to pr the matrix \n",
217 | "def displayMatrix( mat ): \n",
218 | " \n",
219 | " for i in range(0, N): \n",
220 | " \n",
221 | " for j in range(0, N): \n",
222 | " \n",
223 | " print (mat[i][j], end = ' ') \n",
224 | " print (\"\") \n",
225 | " \n",
226 | " \n",
227 | " \n",
228 | " \n",
229 | "# Driver Code \n",
230 | "mat = [[0 for x in range(N)] for y in range(N)] \n",
231 | " \n",
232 | "# Test case 1 \n",
233 | "mat = [ [1, 2, 3, 4 ], \n",
234 | " [5, 6, 7, 8 ], \n",
235 | " [9, 10, 11, 12 ], \n",
236 | " [13, 14, 15, 16 ] ] \n",
237 | " \n",
238 | "''' \n",
239 | "# Test case 2 \n",
240 | "mat = [ [1, 2, 3 ], \n",
241 | " [4, 5, 6 ], \n",
242 | " [7, 8, 9 ] ] \n",
243 | " \n",
244 | "# Test case 3 \n",
245 | "mat = [ [1, 2 ], \n",
246 | " [4, 5 ] ] \n",
247 | " \n",
248 | "'''\n",
249 | " \n",
250 | "rotateMatrix(mat) \n",
251 | " \n",
252 | "# Print rotated matrix \n",
253 | "displayMatrix(mat) "
254 | ]
255 | },
256 | {
257 | "cell_type": "code",
258 | "execution_count": null,
259 | "metadata": {
260 | "collapsed": true
261 | },
262 | "outputs": [],
263 | "source": []
264 | }
265 | ],
266 | "metadata": {
267 | "kernelspec": {
268 | "display_name": "Python 3",
269 | "language": "python",
270 | "name": "python3"
271 | },
272 | "language_info": {
273 | "codemirror_mode": {
274 | "name": "ipython",
275 | "version": 3
276 | },
277 | "file_extension": ".py",
278 | "mimetype": "text/x-python",
279 | "name": "python",
280 | "nbconvert_exporter": "python",
281 | "pygments_lexer": "ipython3",
282 | "version": "3.6.8"
283 | }
284 | },
285 | "nbformat": 4,
286 | "nbformat_minor": 2
287 | }
288 |
--------------------------------------------------------------------------------
/coding_prac/day22.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | " Questions
\n",
8 | "\n",
9 | "##### Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.\n",
10 | "\n",
11 | "##### Example 1:\n",
12 | "\n",
13 | "##### Input: 121\n",
14 | "\n",
15 | "##### Output: true\n",
16 | "\n",
17 | "##### Example 2:\n",
18 | "\n",
19 | "##### Input: -121\n",
20 | "\n",
21 | "##### Output: False\n",
22 | "\n",
23 | "##### Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.\n",
24 | "\n",
25 | "##### Example 3:\n",
26 | "\n",
27 | "##### Input: 10\n",
28 | "\n",
29 | "##### Output: false\n",
30 | "\n",
31 | "##### Explanation: Reads 01 from right to left. Therefore it is not a palindrome.\n"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": 4,
37 | "metadata": {},
38 | "outputs": [
39 | {
40 | "name": "stdout",
41 | "output_type": "stream",
42 | "text": [
43 | "False\n"
44 | ]
45 | }
46 | ],
47 | "source": [
48 | "class Solution:\n",
49 | " def isPalindrome(self, x: int) -> bool:\n",
50 | " a=str(x)\n",
51 | " if a[:]==a[::-1]:\n",
52 | " return True\n",
53 | " else:\n",
54 | " return False\n",
55 | "\n",
56 | "sol=Solution()\n",
57 | "a=sol.isPalindrome(-121)\n",
58 | "print(a)\n",
59 | " "
60 | ]
61 | },
62 | {
63 | "cell_type": "code",
64 | "execution_count": null,
65 | "metadata": {
66 | "collapsed": true
67 | },
68 | "outputs": [],
69 | "source": []
70 | }
71 | ],
72 | "metadata": {
73 | "kernelspec": {
74 | "display_name": "Python 3",
75 | "language": "python",
76 | "name": "python3"
77 | },
78 | "language_info": {
79 | "codemirror_mode": {
80 | "name": "ipython",
81 | "version": 3
82 | },
83 | "file_extension": ".py",
84 | "mimetype": "text/x-python",
85 | "name": "python",
86 | "nbconvert_exporter": "python",
87 | "pygments_lexer": "ipython3",
88 | "version": "3.6.8"
89 | }
90 | },
91 | "nbformat": 4,
92 | "nbformat_minor": 2
93 | }
94 |
--------------------------------------------------------------------------------
/lists/Day 2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "LISTS
\n",
8 | "\n",
9 | "## Questions\n",
10 | "\n",
11 | "Q1. How Can I Sort a List?\n",
12 | "\n",
13 | "Q2. How To Clone Or Copy a List\n",
14 | "\n",
15 | "Q3. How Does List Comprehension Work?\n",
16 | "\n",
17 | "Q4. How Do I Count Occurrences of a List Item?\n",
18 | "\n",
19 | "Q5. How Do I Split a List into Evenly Sized Chunks?\n",
20 | "\n",
21 | "Q6. How Do I Loop over a List?\n",
22 | "\n",
23 | "Q7. How Do I Get an Intersection Of Two Lists?\n",
24 | "\n",
25 | "Q8. How Do I Remove Duplicates From a List?\n",
26 | "\n",
27 | "Q9. What’s The Difference Between The append() and extend() Methods?\n",
28 | "\n",
29 | "Q10. How Do I Create Flat Lists Out Of Lists?"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "## ANSWERS"
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {},
42 | "source": [
43 | "### Q1. How Can I Sort a List?\n",
44 | "You use the sort() method of Python lists or you use the sorted() function and pass a list to it. The sorted() function can be applied to any Iterable object, which means that it also accepts strings, sets, dictionaries when they are passed to it!\n",
45 | "\n",
46 | "### Q2. How To Clone Or Copy a List\n",
47 | "You can slice your original list and store it into a new variable or you can use the built-in list() function. You can also use the copy library with the copy() method. Lastly, if your list contains objects and you want to copy those as well, you can use copy.deepcopy().\n",
48 | "\n",
49 | "### Q3. How Does List Comprehension Work?\n",
50 | "List comprehension is, basically speaking, a way of elegantly constructing your Python lists. The best thing about this for those who love math is the fact that they look a lot like mathematical lists. In in a more general sense, you can also use list comprehension to transform your lists into other lists, which sounds a bit more difficult, doesn’t it?\n",
51 | "\n",
52 | "### Q4 How do i count occurences in the list?\n",
53 | "\n",
54 | "Counting all items in a Python list with count() & Counting all Python list items with Counter()\n",
55 | "\n",
56 | "### Q5. How Do I Split a List into Evenly Sized Chunks?\n",
57 | "To split your list up into parts of the same size, you can resort to the zip() function in combination with iter().\n",
58 | "\n",
59 | "### Q6. How Do I Loop over a List?\n",
60 | "You can easily loop through any list with a for loop.\n",
61 | "\n",
62 | "### Q7. How Do I Get an Intersection Of Two Lists?\n",
63 | "List Intersection Using List Comprehension\n",
64 | "If you want to obtain the intersection of two lists, you can use the filter() function.\n",
65 | "If the order of your elements is not important and if you don’t need to worry about duplicates then you can use set intersection.\n",
66 | "\n",
67 | "### Q8. How Do I Remove Duplicates From a List?\n",
68 | "It’s best to select a set if you want to store a unique collection of unordered items.\n",
69 | "To create a set from any iterable, you can simply pass it to the built-in set() function. If you later need a real list again, you can similarly pass the set to the list() function.\n",
70 | "\n",
71 | "### Q9. What’s The Difference Between The append() and extend() Methods?\n",
72 | "The extend() method, on the one hand, takes an iterable (that’s right, it takes a list, set, tuple or string!), and adds each element of the iterable to the list one at a time.\n",
73 | "The append() method , on the other hand, adds its argument to the end of the list as a single item, which means that when the append() function takes an iterable as its argument, it will treat it as a single object.\n",
74 | "\n",
75 | "### Q10. How Do I Create Flat Lists Out Of Lists?\n",
76 | "To make a simple list out of a list of lists, you can use the sum() function. Just don’t forget to pass your list and an empty list to it."
77 | ]
78 | },
79 | {
80 | "cell_type": "code",
81 | "execution_count": null,
82 | "metadata": {},
83 | "outputs": [],
84 | "source": []
85 | },
86 | {
87 | "cell_type": "code",
88 | "execution_count": null,
89 | "metadata": {
90 | "collapsed": true
91 | },
92 | "outputs": [],
93 | "source": []
94 | },
95 | {
96 | "cell_type": "code",
97 | "execution_count": null,
98 | "metadata": {},
99 | "outputs": [],
100 | "source": []
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": null,
105 | "metadata": {
106 | "collapsed": true
107 | },
108 | "outputs": [],
109 | "source": []
110 | }
111 | ],
112 | "metadata": {
113 | "kernelspec": {
114 | "display_name": "Python 3",
115 | "language": "python",
116 | "name": "python3"
117 | },
118 | "language_info": {
119 | "codemirror_mode": {
120 | "name": "ipython",
121 | "version": 3
122 | },
123 | "file_extension": ".py",
124 | "mimetype": "text/x-python",
125 | "name": "python",
126 | "nbconvert_exporter": "python",
127 | "pygments_lexer": "ipython3",
128 | "version": "3.6.8"
129 | }
130 | },
131 | "nbformat": 4,
132 | "nbformat_minor": 2
133 | }
134 |
--------------------------------------------------------------------------------
/lists/Day1.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | " Lists
\n",
8 | "\n",
9 | "## Questions\n",
10 | "\n",
11 | "Q1. When should we prefer using tuples over list?\n",
12 | "\n",
13 | "Q2. When should we prefer to use dictionaries over lists?\n",
14 | "\n",
15 | "Q3. When should we prefer to use sets over lists?\n",
16 | "\n",
17 | "Q4. When should we actually prefer to use lists?\n",
18 | "\n",
19 | "Q5. Easy Peasy : how do you select an element from a list?\n",
20 | "\n",
21 | "Q6. How do you convert a python list to a string?\n",
22 | "\n",
23 | "Q7. How do you convert a python list to a set?\n",
24 | "\n",
25 | "Q8. How do you convert a python list to a tuple?\n",
26 | "\n",
27 | "Q9. Again Easy Peasy : how do you find length of a python list?\n",
28 | "\n",
29 | "Q10. What is the difference between append and + operator when you concatenate two lists?"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "## Thanks Sourav kumar for the answers\n",
37 | "\n",
38 | "1. we can use tuples when we don't wanna change the values of items , that is keeping it immutable.\n",
39 | "2. if we wanna store the items on the basis of key , that is faster searching of values based on index value.\n",
40 | "3. When you wanna keep non-repeating values, then use set , also to check membership of a item , set is more faster 0(1) in average whereas 0(k) for list where k is length of list.\n",
41 | "4. list is resizeable , keeps order so you can track .\n",
42 | "5. say , you wanna select a element at index at '4' , and (index starts at 0 in python)\n",
43 | "\n"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": 1,
49 | "metadata": {
50 | "collapsed": true
51 | },
52 | "outputs": [],
53 | "source": [
54 | "a=[10,20,20]"
55 | ]
56 | },
57 | {
58 | "cell_type": "code",
59 | "execution_count": 2,
60 | "metadata": {},
61 | "outputs": [
62 | {
63 | "data": {
64 | "text/plain": [
65 | "20"
66 | ]
67 | },
68 | "execution_count": 2,
69 | "metadata": {},
70 | "output_type": "execute_result"
71 | }
72 | ],
73 | "source": [
74 | "a[1]"
75 | ]
76 | },
77 | {
78 | "cell_type": "code",
79 | "execution_count": 4,
80 | "metadata": {},
81 | "outputs": [
82 | {
83 | "data": {
84 | "text/plain": [
85 | "'hello world'"
86 | ]
87 | },
88 | "execution_count": 4,
89 | "metadata": {},
90 | "output_type": "execute_result"
91 | }
92 | ],
93 | "source": [
94 | "a=[\"hello\",\"world\"]\n",
95 | "\" \".join(a)"
96 | ]
97 | },
98 | {
99 | "cell_type": "code",
100 | "execution_count": 5,
101 | "metadata": {},
102 | "outputs": [
103 | {
104 | "data": {
105 | "text/plain": [
106 | "{'hello', 'world'}"
107 | ]
108 | },
109 | "execution_count": 5,
110 | "metadata": {},
111 | "output_type": "execute_result"
112 | }
113 | ],
114 | "source": [
115 | "set(a)"
116 | ]
117 | },
118 | {
119 | "cell_type": "code",
120 | "execution_count": 6,
121 | "metadata": {},
122 | "outputs": [
123 | {
124 | "data": {
125 | "text/plain": [
126 | "('hello', 'world')"
127 | ]
128 | },
129 | "execution_count": 6,
130 | "metadata": {},
131 | "output_type": "execute_result"
132 | }
133 | ],
134 | "source": [
135 | "tuple(a)"
136 | ]
137 | },
138 | {
139 | "cell_type": "code",
140 | "execution_count": 7,
141 | "metadata": {},
142 | "outputs": [
143 | {
144 | "data": {
145 | "text/plain": [
146 | "2"
147 | ]
148 | },
149 | "execution_count": 7,
150 | "metadata": {},
151 | "output_type": "execute_result"
152 | }
153 | ],
154 | "source": [
155 | "len(a)"
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": 8,
161 | "metadata": {
162 | "collapsed": true
163 | },
164 | "outputs": [],
165 | "source": [
166 | "l1 = [1, 2, 3, 4, 5]"
167 | ]
168 | },
169 | {
170 | "cell_type": "code",
171 | "execution_count": 9,
172 | "metadata": {
173 | "collapsed": true
174 | },
175 | "outputs": [],
176 | "source": [
177 | "l2 = [6, 7, 8, 9, 10]"
178 | ]
179 | },
180 | {
181 | "cell_type": "code",
182 | "execution_count": 10,
183 | "metadata": {},
184 | "outputs": [
185 | {
186 | "data": {
187 | "text/plain": [
188 | "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
189 | ]
190 | },
191 | "execution_count": 10,
192 | "metadata": {},
193 | "output_type": "execute_result"
194 | }
195 | ],
196 | "source": [
197 | "l1 + l2"
198 | ]
199 | },
200 | {
201 | "cell_type": "code",
202 | "execution_count": 11,
203 | "metadata": {
204 | "collapsed": true
205 | },
206 | "outputs": [],
207 | "source": [
208 | "l1.append(l2)"
209 | ]
210 | },
211 | {
212 | "cell_type": "code",
213 | "execution_count": 12,
214 | "metadata": {},
215 | "outputs": [
216 | {
217 | "data": {
218 | "text/plain": [
219 | "[1, 2, 3, 4, 5, [6, 7, 8, 9, 10]]"
220 | ]
221 | },
222 | "execution_count": 12,
223 | "metadata": {},
224 | "output_type": "execute_result"
225 | }
226 | ],
227 | "source": [
228 | "l1"
229 | ]
230 | },
231 | {
232 | "cell_type": "code",
233 | "execution_count": null,
234 | "metadata": {
235 | "collapsed": true
236 | },
237 | "outputs": [],
238 | "source": []
239 | }
240 | ],
241 | "metadata": {
242 | "kernelspec": {
243 | "display_name": "Python 3",
244 | "language": "python",
245 | "name": "python3"
246 | },
247 | "language_info": {
248 | "codemirror_mode": {
249 | "name": "ipython",
250 | "version": 3
251 | },
252 | "file_extension": ".py",
253 | "mimetype": "text/x-python",
254 | "name": "python",
255 | "nbconvert_exporter": "python",
256 | "pygments_lexer": "ipython3",
257 | "version": "3.6.8"
258 | }
259 | },
260 | "nbformat": 4,
261 | "nbformat_minor": 2
262 | }
263 |
--------------------------------------------------------------------------------
/lists/day19.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Day 19
\n",
8 | "\n",
9 | "## General Questions"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {},
15 | "source": [
16 | "### 1. What is Python really?\n",
17 | "### 2. Fill in the missing code:def print_directory_contents(sPath):\n",
18 | "\n",
19 | " \"\"\"\n",
20 | " \n",
21 | " This function takes the name of a directory\n",
22 | " \n",
23 | " and prints out the paths files within that\n",
24 | " \n",
25 | " directory as well as any files contained in\n",
26 | " \n",
27 | " contained directories. \n",
28 | " \n",
29 | " This function is similar to os.walk. Please don't\n",
30 | "\n",
31 | " use os.walk in your answer. We are interested in your\n",
32 | " \n",
33 | " ability to work with nested structures.\n",
34 | " \n",
35 | " \"\"\"\n",
36 | " \n",
37 | " fill_this_in\n",
38 | " \n",
39 | "### 3.Looking at the below code, write down the final values of A0, A1, ...An.\n",
40 | " \n",
41 | " A0 = dict(zip(('a','b','c','d','e'),(1,2,3,4,5)))\n",
42 | "\n",
43 | " A1 = range(10)\n",
44 | "\n",
45 | " A2 = sorted([i for i in A1 if i in A0])\n",
46 | "\n",
47 | " A3 = sorted([A0[s] for s in A0])\n",
48 | "\n",
49 | " A4 = [i for i in A1 if i in A3]\n",
50 | "\n",
51 | " A5 = {i:i*i for i in A1}\n",
52 | "\n",
53 | " A6 = [[i,i*i] for i in A1]\n",
54 | "\n",
55 | "### 4.Python and multi-threading. Is it a good idea? List some ways to get some Python code to run in a parallel way.\n",
56 | "\n",
57 | "### 5.How do you keep track of different versions of your code?"
58 | ]
59 | },
60 | {
61 | "cell_type": "markdown",
62 | "metadata": {},
63 | "source": [
64 | "## Q1 What is Python really?\n",
65 | "\n",
66 | "1. Python is an interpreted language. That means that, unlike languages like C and its variants, Python does not need to be compiled before it is run. Other interpreted languages include PHP and Ruby.\n",
67 | "\n",
68 | "2. Python is dynamically typed, this means that you don't need to state the types of variables when you declare them or anything like that. You can do things like x=111 and then x=\"I'm a string\" without error\n",
69 | "\n",
70 | "3. Python is well suited to object orientated programming in that it allows the definition of classes along with composition and inheritance. Python does not have access specifiers (like C++'s public, private), the justification for this point is given as \"we are all adults here\"\n",
71 | "\n",
72 | "4. In Python, functions are first-class objects. This means that they can be assigned to variables, returned from other functions and passed into functions. Classes are also first class objects\n",
73 | "\n",
74 | "5. Writing Python code is quick but running it is often slower than compiled languages. Fortunately, Python allows the inclusion of C based extensions so bottlenecks can be optimised away and often are. The numpy package is a good example of this, it's really quite quick because a lot of the number crunching it does isn't actually done by Python\n",
75 | "\n",
76 | "6. Python finds use in many spheres - web applications, automation, scientific modelling, big data applications and many more. It's also often used as \"glue\" code to get other languages and components to play nice.\n",
77 | "\n",
78 | "7. Python makes difficult things easy so programmers can focus on overriding algorithms and structures rather than nitty-gritty low level details.\n"
79 | ]
80 | },
81 | {
82 | "cell_type": "code",
83 | "execution_count": 2,
84 | "metadata": {},
85 | "outputs": [],
86 | "source": [
87 | "# Q2 \n",
88 | "import os\n"
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": 32,
94 | "metadata": {
95 | "collapsed": true
96 | },
97 | "outputs": [],
98 | "source": [
99 | "def fun(dir1):\n",
100 | " for i in os.listdir(dir1):\n",
101 | " j=os.path.join(dir1,i)\n",
102 | " if os.path.isfile(j):\n",
103 | " print(j)\n",
104 | " else:\n",
105 | " print(j)\n",
106 | " fun(j)\n"
107 | ]
108 | },
109 | {
110 | "cell_type": "code",
111 | "execution_count": 33,
112 | "metadata": {},
113 | "outputs": [
114 | {
115 | "name": "stdout",
116 | "output_type": "stream",
117 | "text": [
118 | "./ac\n",
119 | "./ac/abc\n",
120 | "./Day1.ipynb\n",
121 | "./.ipynb_checkpoints\n",
122 | "./.ipynb_checkpoints/Day 2-checkpoint.ipynb\n",
123 | "./.ipynb_checkpoints/Day1-checkpoint.ipynb\n",
124 | "./.ipynb_checkpoints/day19-checkpoint.ipynb\n",
125 | "./Day 2.ipynb\n",
126 | "./day19.ipynb\n"
127 | ]
128 | }
129 | ],
130 | "source": [
131 | "fun(\"./\")"
132 | ]
133 | },
134 | {
135 | "cell_type": "code",
136 | "execution_count": 18,
137 | "metadata": {},
138 | "outputs": [],
139 | "source": [
140 | "#3\n",
141 | "A0=dict(zip(('a','b','c','d','e'),(1,2,3,4,5)))\n",
142 | "A1 = range(10)\n",
143 | "A2 = sorted([i for i in A1 if i in A0])\n",
144 | "A3 = sorted([A0[s] for s in A0])\n",
145 | "A4 = [i for i in A1 if i in A3]\n",
146 | "A5 = {i:i*i for i in A1}\n",
147 | "A6 = [[i,i*i] for i in A1]"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": 24,
153 | "metadata": {},
154 | "outputs": [
155 | {
156 | "name": "stdout",
157 | "output_type": "stream",
158 | "text": [
159 | "{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}\n"
160 | ]
161 | }
162 | ],
163 | "source": [
164 | "print(A0)"
165 | ]
166 | },
167 | {
168 | "cell_type": "code",
169 | "execution_count": 25,
170 | "metadata": {},
171 | "outputs": [
172 | {
173 | "name": "stdout",
174 | "output_type": "stream",
175 | "text": [
176 | "range(0, 10)\n"
177 | ]
178 | }
179 | ],
180 | "source": [
181 | "print(A1)"
182 | ]
183 | },
184 | {
185 | "cell_type": "code",
186 | "execution_count": 26,
187 | "metadata": {},
188 | "outputs": [
189 | {
190 | "name": "stdout",
191 | "output_type": "stream",
192 | "text": [
193 | "[]\n"
194 | ]
195 | }
196 | ],
197 | "source": [
198 | "print(A2)"
199 | ]
200 | },
201 | {
202 | "cell_type": "code",
203 | "execution_count": 27,
204 | "metadata": {},
205 | "outputs": [
206 | {
207 | "name": "stdout",
208 | "output_type": "stream",
209 | "text": [
210 | "[1, 2, 3, 4, 5]\n"
211 | ]
212 | }
213 | ],
214 | "source": [
215 | "print(A3)"
216 | ]
217 | },
218 | {
219 | "cell_type": "code",
220 | "execution_count": 28,
221 | "metadata": {},
222 | "outputs": [
223 | {
224 | "name": "stdout",
225 | "output_type": "stream",
226 | "text": [
227 | "[1, 2, 3, 4, 5]\n"
228 | ]
229 | }
230 | ],
231 | "source": [
232 | "print(A4)"
233 | ]
234 | },
235 | {
236 | "cell_type": "code",
237 | "execution_count": 29,
238 | "metadata": {},
239 | "outputs": [
240 | {
241 | "name": "stdout",
242 | "output_type": "stream",
243 | "text": [
244 | "{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}\n"
245 | ]
246 | }
247 | ],
248 | "source": [
249 | "print(A5)"
250 | ]
251 | },
252 | {
253 | "cell_type": "code",
254 | "execution_count": 30,
255 | "metadata": {},
256 | "outputs": [
257 | {
258 | "name": "stdout",
259 | "output_type": "stream",
260 | "text": [
261 | "[[0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]]\n"
262 | ]
263 | }
264 | ],
265 | "source": [
266 | "print(A6)"
267 | ]
268 | },
269 | {
270 | "cell_type": "markdown",
271 | "metadata": {},
272 | "source": [
273 | "## Q4 Python and multi-threading. Is it a good idea? List some ways to get some Python code to run in a parallel way.?\n",
274 | "\n",
275 | "Python doesn't allow multi-threading in the truest sense of the word. It has a multi-threading package but if you want to multi-thread to speed your code up, then it's usually not a good idea to use it. Python has a construct called the Global Interpreter Lock (GIL). The GIL makes sure that only one of your 'threads' can execute at any one time. A thread acquires the GIL, does a little work, then passes the GIL onto the next thread. This happens very quickly so to the human eye it may seem like your threads are executing in parallel, but they are really just taking turns using the same CPU core. All this GIL passing adds overhead to execution. This means that if you want to make your code run faster then using the threading package often isn't a good idea.\n",
276 | "\n",
277 | "There are reasons to use Python's threading package. If you want to run some things simultaneously, and efficiency is not a concern, then it's totally fine and convenient. Or if you are running code that needs to wait for something (like some IO) then it could make a lot of sense. But the threading library won't let you use extra CPU cores.\n",
278 | "\n",
279 | "Multi-threading can be outsourced to the operating system (by doing multi-processing), some external application that calls your Python code (eg, Spark or Hadoop), or some code that your Python code calls (eg: you could have your Python code call a C function that does the expensive multi-threaded stuff)."
280 | ]
281 | },
282 | {
283 | "cell_type": "markdown",
284 | "metadata": {},
285 | "source": [
286 | "## Q5.How do you keep track of different versions of your code?\n",
287 | "\n",
288 | "Version control! At this point, you should act excited and tell them how you even use Git (or whatever is your favorite) to keep track of correspondence with Granny. Git is my preferred version control system, but there are others, for example subversion."
289 | ]
290 | },
291 | {
292 | "cell_type": "code",
293 | "execution_count": null,
294 | "metadata": {
295 | "collapsed": true
296 | },
297 | "outputs": [],
298 | "source": []
299 | }
300 | ],
301 | "metadata": {
302 | "kernelspec": {
303 | "display_name": "Python 3",
304 | "language": "python",
305 | "name": "python3"
306 | },
307 | "language_info": {
308 | "codemirror_mode": {
309 | "name": "ipython",
310 | "version": 3
311 | },
312 | "file_extension": ".py",
313 | "mimetype": "text/x-python",
314 | "name": "python",
315 | "nbconvert_exporter": "python",
316 | "pygments_lexer": "ipython3",
317 | "version": "3.6.8"
318 | }
319 | },
320 | "nbformat": 4,
321 | "nbformat_minor": 2
322 | }
323 |
--------------------------------------------------------------------------------
/numpy/Day 6.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "NUMPY\n",
8 | "## Questions \n",
9 | "31. How to find the percentile scores of a numpy array?\n",
10 | "32. How to insert values at random positions in an array?\n",
11 | "33. How to find the position of missing values in numpy array?\n",
12 | "34. How to filter a numpy array based on two or more conditions?\n",
13 | "35. How to drop rows that contain a missing value from a numpy array?\n",
14 | "36. How to find the correlation between two columns of a numpy array?\n",
15 | "37. How to find if a given array has any null values?\n",
16 | "38. How to replace all missing values with 0 in a numpy array?\n",
17 | "39. How to find the count of unique values in a numpy array?\n",
18 | "40. How to convert a numeric to a categorical (text) array?\n",
19 | "41. How to create a new column from existing columns of a numpy array?\n",
20 | "42. How to do probabilistic sampling in numpy?\n",
21 | "43. How to get the second largest value of an array when grouped by another array?\n",
22 | "44. How to sort a 2D array by a column\n",
23 | "45. How to find the most frequent value in a numpy array?\n",
24 | "46. How to find the position of the first occurrence of a value greater than a given value?\n",
25 | "47. How to replace all values greater than a given value to a given cutoff?\n",
26 | "48. How to get the positions of top n values from a numpy array?\n",
27 | "49. How to compute the row wise counts of all possible values in an array?\n",
28 | "50. How to convert an array of arrays into a flat 1d array"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": 1,
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "#1 percentile score\n",
38 | "import numpy as np\n",
39 | "a=np.array([1,2,3,4,5,67,8])"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": 2,
45 | "metadata": {},
46 | "outputs": [
47 | {
48 | "data": {
49 | "text/plain": [
50 | "array([ 1, 2, 3, 4, 5, 67, 8])"
51 | ]
52 | },
53 | "execution_count": 2,
54 | "metadata": {},
55 | "output_type": "execute_result"
56 | }
57 | ],
58 | "source": [
59 | "a"
60 | ]
61 | },
62 | {
63 | "cell_type": "code",
64 | "execution_count": 3,
65 | "metadata": {},
66 | "outputs": [
67 | {
68 | "data": {
69 | "text/plain": [
70 | "3.0999999999999996"
71 | ]
72 | },
73 | "execution_count": 3,
74 | "metadata": {},
75 | "output_type": "execute_result"
76 | }
77 | ],
78 | "source": [
79 | "np.percentile(a,35)"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": 4,
85 | "metadata": {},
86 | "outputs": [],
87 | "source": [
88 | "#2 insertion at values\n",
89 | "a=np.insert(a,5,43)"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": 5,
95 | "metadata": {},
96 | "outputs": [
97 | {
98 | "data": {
99 | "text/plain": [
100 | "array([ 1, 2, 3, 4, 5, 43, 67, 8])"
101 | ]
102 | },
103 | "execution_count": 5,
104 | "metadata": {},
105 | "output_type": "execute_result"
106 | }
107 | ],
108 | "source": [
109 | "a"
110 | ]
111 | },
112 | {
113 | "cell_type": "code",
114 | "execution_count": 6,
115 | "metadata": {
116 | "collapsed": true
117 | },
118 | "outputs": [],
119 | "source": [
120 | "#3 position of missing values\n",
121 | "idx=np.where(np.isnan(a))"
122 | ]
123 | },
124 | {
125 | "cell_type": "code",
126 | "execution_count": 7,
127 | "metadata": {},
128 | "outputs": [
129 | {
130 | "data": {
131 | "text/plain": [
132 | "(array([], dtype=int64),)"
133 | ]
134 | },
135 | "execution_count": 7,
136 | "metadata": {},
137 | "output_type": "execute_result"
138 | }
139 | ],
140 | "source": [
141 | "idx"
142 | ]
143 | },
144 | {
145 | "cell_type": "code",
146 | "execution_count": 8,
147 | "metadata": {
148 | "collapsed": true
149 | },
150 | "outputs": [],
151 | "source": [
152 | "#4 filtering a numpy array\n",
153 | "a=a[(a>2) & (a<50)]"
154 | ]
155 | },
156 | {
157 | "cell_type": "code",
158 | "execution_count": 9,
159 | "metadata": {},
160 | "outputs": [
161 | {
162 | "data": {
163 | "text/plain": [
164 | "array([ 3, 4, 5, 43, 8])"
165 | ]
166 | },
167 | "execution_count": 9,
168 | "metadata": {},
169 | "output_type": "execute_result"
170 | }
171 | ],
172 | "source": [
173 | "a"
174 | ]
175 | },
176 | {
177 | "cell_type": "code",
178 | "execution_count": 10,
179 | "metadata": {},
180 | "outputs": [
181 | {
182 | "data": {
183 | "text/plain": [
184 | "array([[ 3, 4, 5, 43, 8]])"
185 | ]
186 | },
187 | "execution_count": 10,
188 | "metadata": {},
189 | "output_type": "execute_result"
190 | }
191 | ],
192 | "source": [
193 | "#5 drop rows\n",
194 | "a[np.all(np.isfinite(a), axis=0)]"
195 | ]
196 | },
197 | {
198 | "cell_type": "code",
199 | "execution_count": 11,
200 | "metadata": {},
201 | "outputs": [
202 | {
203 | "data": {
204 | "text/plain": [
205 | "array([ 3, 4, 5, 43, 8])"
206 | ]
207 | },
208 | "execution_count": 11,
209 | "metadata": {},
210 | "output_type": "execute_result"
211 | }
212 | ],
213 | "source": [
214 | "a"
215 | ]
216 | },
217 | {
218 | "cell_type": "code",
219 | "execution_count": 12,
220 | "metadata": {
221 | "collapsed": true
222 | },
223 | "outputs": [],
224 | "source": [
225 | "b=np.array([1,33,4,5,6,np.nan])"
226 | ]
227 | },
228 | {
229 | "cell_type": "code",
230 | "execution_count": 13,
231 | "metadata": {},
232 | "outputs": [
233 | {
234 | "data": {
235 | "text/plain": [
236 | "0.8717541573048718"
237 | ]
238 | },
239 | "execution_count": 13,
240 | "metadata": {},
241 | "output_type": "execute_result"
242 | }
243 | ],
244 | "source": [
245 | "#6 correlation between two columns\n",
246 | "url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'\n",
247 | "iris = np.genfromtxt(url, delimiter=',', dtype='float', usecols=[0,1,2,3])\n",
248 | "\n",
249 | "# Solution 1\n",
250 | "np.corrcoef(iris[:, 0], iris[:, 2])[0, 1]\n"
251 | ]
252 | },
253 | {
254 | "cell_type": "code",
255 | "execution_count": 14,
256 | "metadata": {},
257 | "outputs": [
258 | {
259 | "data": {
260 | "text/plain": [
261 | "array([False, False, False, False, False, True])"
262 | ]
263 | },
264 | "execution_count": 14,
265 | "metadata": {},
266 | "output_type": "execute_result"
267 | }
268 | ],
269 | "source": [
270 | "#7 find if array has null values\n",
271 | "\n",
272 | "np.isnan(b)"
273 | ]
274 | },
275 | {
276 | "cell_type": "code",
277 | "execution_count": 15,
278 | "metadata": {},
279 | "outputs": [],
280 | "source": [
281 | "#8 replace null with 0\n",
282 | "b[np.where(np.isnan(b))]=0"
283 | ]
284 | },
285 | {
286 | "cell_type": "code",
287 | "execution_count": 16,
288 | "metadata": {},
289 | "outputs": [
290 | {
291 | "data": {
292 | "text/plain": [
293 | "array([ 1., 33., 4., 5., 6., 0.])"
294 | ]
295 | },
296 | "execution_count": 16,
297 | "metadata": {},
298 | "output_type": "execute_result"
299 | }
300 | ],
301 | "source": [
302 | "b"
303 | ]
304 | },
305 | {
306 | "cell_type": "code",
307 | "execution_count": 17,
308 | "metadata": {},
309 | "outputs": [
310 | {
311 | "data": {
312 | "text/plain": [
313 | "5"
314 | ]
315 | },
316 | "execution_count": 17,
317 | "metadata": {},
318 | "output_type": "execute_result"
319 | }
320 | ],
321 | "source": [
322 | "#9 count unique values\n",
323 | "len(np.unique(a))"
324 | ]
325 | },
326 | {
327 | "cell_type": "code",
328 | "execution_count": 18,
329 | "metadata": {},
330 | "outputs": [
331 | {
332 | "data": {
333 | "text/plain": [
334 | "'[ 3 4 5 43 8]'"
335 | ]
336 | },
337 | "execution_count": 18,
338 | "metadata": {},
339 | "output_type": "execute_result"
340 | }
341 | ],
342 | "source": [
343 | "#10 numerical to categorical array\n",
344 | "np.array2string(a)"
345 | ]
346 | },
347 | {
348 | "cell_type": "code",
349 | "execution_count": 19,
350 | "metadata": {},
351 | "outputs": [
352 | {
353 | "data": {
354 | "text/plain": [
355 | "array([ 3., 4., 5., 43., 8., 0.])"
356 | ]
357 | },
358 | "execution_count": 19,
359 | "metadata": {},
360 | "output_type": "execute_result"
361 | }
362 | ],
363 | "source": [
364 | "#11 create new columns from existing columns\n",
365 | "np.append(a,np.zeros(1))"
366 | ]
367 | },
368 | {
369 | "cell_type": "code",
370 | "execution_count": 20,
371 | "metadata": {},
372 | "outputs": [
373 | {
374 | "data": {
375 | "text/plain": [
376 | "array([3, 4, 5, 8, 5])"
377 | ]
378 | },
379 | "execution_count": 20,
380 | "metadata": {},
381 | "output_type": "execute_result"
382 | }
383 | ],
384 | "source": [
385 | "# 12 probabilistic sampling in numpy array\n",
386 | "np.random.choice(a,5)"
387 | ]
388 | },
389 | {
390 | "cell_type": "code",
391 | "execution_count": 21,
392 | "metadata": {},
393 | "outputs": [
394 | {
395 | "data": {
396 | "text/plain": [
397 | "8"
398 | ]
399 | },
400 | "execution_count": 21,
401 | "metadata": {},
402 | "output_type": "execute_result"
403 | }
404 | ],
405 | "source": [
406 | "#13\n",
407 | "import heapq\n",
408 | "heapq.nlargest(2,a)[1]"
409 | ]
410 | },
411 | {
412 | "cell_type": "code",
413 | "execution_count": 22,
414 | "metadata": {},
415 | "outputs": [
416 | {
417 | "data": {
418 | "text/plain": [
419 | "array([[3, 1],\n",
420 | " [1, 2]])"
421 | ]
422 | },
423 | "execution_count": 22,
424 | "metadata": {},
425 | "output_type": "execute_result"
426 | }
427 | ],
428 | "source": [
429 | "#14\n",
430 | "d=np.array([[1,2],[3,1]])\n",
431 | "d[d[:,1].argsort()]"
432 | ]
433 | },
434 | {
435 | "cell_type": "code",
436 | "execution_count": 23,
437 | "metadata": {},
438 | "outputs": [
439 | {
440 | "name": "stdout",
441 | "output_type": "stream",
442 | "text": [
443 | "1.5\n"
444 | ]
445 | }
446 | ],
447 | "source": [
448 | "#15\n",
449 | "vals, counts = np.unique(iris[:, 2], return_counts=True)\n",
450 | "print(vals[np.argmax(counts)])"
451 | ]
452 | },
453 | {
454 | "cell_type": "code",
455 | "execution_count": 24,
456 | "metadata": {},
457 | "outputs": [
458 | {
459 | "data": {
460 | "text/plain": [
461 | "3"
462 | ]
463 | },
464 | "execution_count": 24,
465 | "metadata": {},
466 | "output_type": "execute_result"
467 | }
468 | ],
469 | "source": [
470 | "#16\n",
471 | "np.where(a>5)[0][0]"
472 | ]
473 | },
474 | {
475 | "cell_type": "code",
476 | "execution_count": 25,
477 | "metadata": {},
478 | "outputs": [],
479 | "source": [
480 | "#17\n",
481 | "cut=10\n",
482 | "a[np.where(a>cut)]=20"
483 | ]
484 | },
485 | {
486 | "cell_type": "code",
487 | "execution_count": 26,
488 | "metadata": {},
489 | "outputs": [
490 | {
491 | "data": {
492 | "text/plain": [
493 | "array([ 3, 4, 5, 20, 8])"
494 | ]
495 | },
496 | "execution_count": 26,
497 | "metadata": {},
498 | "output_type": "execute_result"
499 | }
500 | ],
501 | "source": [
502 | "a"
503 | ]
504 | },
505 | {
506 | "cell_type": "code",
507 | "execution_count": 27,
508 | "metadata": {},
509 | "outputs": [
510 | {
511 | "data": {
512 | "text/plain": [
513 | "[20, 8, 5, 4, 3]"
514 | ]
515 | },
516 | "execution_count": 27,
517 | "metadata": {},
518 | "output_type": "execute_result"
519 | }
520 | ],
521 | "source": [
522 | "#18\n",
523 | "heapq.nlargest(5,a)"
524 | ]
525 | },
526 | {
527 | "cell_type": "code",
528 | "execution_count": 28,
529 | "metadata": {},
530 | "outputs": [
531 | {
532 | "name": "stdout",
533 | "output_type": "stream",
534 | "text": [
535 | "[ 1 2 3 4 5 6 7 8 9 10]\n"
536 | ]
537 | },
538 | {
539 | "data": {
540 | "text/plain": [
541 | "[[1, 0, 0, 0, 0],\n",
542 | " [0, 1, 0, 0, 0],\n",
543 | " [0, 0, 1, 0, 0],\n",
544 | " [0, 0, 0, 0, 1],\n",
545 | " [0, 0, 0, 1, 0]]"
546 | ]
547 | },
548 | "execution_count": 28,
549 | "metadata": {},
550 | "output_type": "execute_result"
551 | }
552 | ],
553 | "source": [
554 | "#19\n",
555 | "# Solution\n",
556 | "def counts_of_all_values_rowwise(arr2d):\n",
557 | " # Unique values and its counts row wise\n",
558 | " num_counts_array = [np.unique(row, return_counts=True) for row in arr2d]\n",
559 | "\n",
560 | " # Counts of all values row wise\n",
561 | " return([[int(b[a==i]) if i in a else 0 for i in np.unique(arr2d)] for a, b in num_counts_array])\n",
562 | "\n",
563 | "# Print\n",
564 | "print(np.arange(1,11))\n",
565 | "counts_of_all_values_rowwise(a)"
566 | ]
567 | },
568 | {
569 | "cell_type": "code",
570 | "execution_count": 29,
571 | "metadata": {},
572 | "outputs": [
573 | {
574 | "data": {
575 | "text/plain": [
576 | "array([ 3, 4, 5, 20, 8])"
577 | ]
578 | },
579 | "execution_count": 29,
580 | "metadata": {},
581 | "output_type": "execute_result"
582 | }
583 | ],
584 | "source": [
585 | "#20\n",
586 | "a.flatten()"
587 | ]
588 | },
589 | {
590 | "cell_type": "code",
591 | "execution_count": null,
592 | "metadata": {
593 | "collapsed": true
594 | },
595 | "outputs": [],
596 | "source": []
597 | },
598 | {
599 | "cell_type": "code",
600 | "execution_count": null,
601 | "metadata": {
602 | "collapsed": true
603 | },
604 | "outputs": [],
605 | "source": []
606 | }
607 | ],
608 | "metadata": {
609 | "kernelspec": {
610 | "display_name": "Python 3",
611 | "language": "python",
612 | "name": "python3"
613 | },
614 | "language_info": {
615 | "codemirror_mode": {
616 | "name": "ipython",
617 | "version": 3
618 | },
619 | "file_extension": ".py",
620 | "mimetype": "text/x-python",
621 | "name": "python",
622 | "nbconvert_exporter": "python",
623 | "pygments_lexer": "ipython3",
624 | "version": "3.6.8"
625 | }
626 | },
627 | "nbformat": 4,
628 | "nbformat_minor": 2
629 | }
630 |
--------------------------------------------------------------------------------
/numpy/Day3.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "collapsed": true
7 | },
8 | "source": [
9 | "Numpy Array
\n",
10 | "\n",
11 | "## Questions\n",
12 | "\n",
13 | "1. Import numpy as np and see the version\n",
14 | "\n",
15 | "2. How to create a 1D array?\n",
16 | "\n",
17 | "3. How to create a boolean array?\n",
18 | "\n",
19 | "4. How to extract items that satisfy a given condition from 1D array?\n",
20 | "\n",
21 | "5. How to replace items that satisfy a condition with another value in numpy array?\n",
22 | "\n",
23 | "6. How to replace items that satisfy a condition without affecting the original array?\n",
24 | "\n",
25 | "7. How to reshape an array?\n",
26 | "\n",
27 | "8. How to stack two arrays vertically?\n",
28 | "\n",
29 | "9. How to stack two arrays horizontally?\n",
30 | "\n",
31 | "10. How to generate custom sequences in numpy without hardcoding?"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": 2,
37 | "metadata": {
38 | "collapsed": true
39 | },
40 | "outputs": [],
41 | "source": [
42 | "#importing numpy\n",
43 | "import numpy as np"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": 3,
49 | "metadata": {},
50 | "outputs": [
51 | {
52 | "data": {
53 | "text/plain": [
54 | "'1.15.0'"
55 | ]
56 | },
57 | "execution_count": 3,
58 | "metadata": {},
59 | "output_type": "execute_result"
60 | }
61 | ],
62 | "source": [
63 | "#version\n",
64 | "np.__version__"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": 4,
70 | "metadata": {
71 | "collapsed": true
72 | },
73 | "outputs": [],
74 | "source": [
75 | "#1-D array"
76 | ]
77 | },
78 | {
79 | "cell_type": "code",
80 | "execution_count": 5,
81 | "metadata": {
82 | "collapsed": true
83 | },
84 | "outputs": [],
85 | "source": [
86 | "one_d=np.array([1,2,3])"
87 | ]
88 | },
89 | {
90 | "cell_type": "code",
91 | "execution_count": 6,
92 | "metadata": {},
93 | "outputs": [
94 | {
95 | "data": {
96 | "text/plain": [
97 | "array([1, 2, 3])"
98 | ]
99 | },
100 | "execution_count": 6,
101 | "metadata": {},
102 | "output_type": "execute_result"
103 | }
104 | ],
105 | "source": [
106 | "one_d"
107 | ]
108 | },
109 | {
110 | "cell_type": "code",
111 | "execution_count": 7,
112 | "metadata": {
113 | "collapsed": true
114 | },
115 | "outputs": [],
116 | "source": [
117 | "#two_d array\n",
118 | "two_d=np.array([[1,2,3],[4,5,6]])"
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": 8,
124 | "metadata": {},
125 | "outputs": [
126 | {
127 | "data": {
128 | "text/plain": [
129 | "array([[1, 2, 3],\n",
130 | " [4, 5, 6]])"
131 | ]
132 | },
133 | "execution_count": 8,
134 | "metadata": {},
135 | "output_type": "execute_result"
136 | }
137 | ],
138 | "source": [
139 | "two_d"
140 | ]
141 | },
142 | {
143 | "cell_type": "code",
144 | "execution_count": 9,
145 | "metadata": {
146 | "collapsed": true
147 | },
148 | "outputs": [],
149 | "source": [
150 | "#boolean array\n",
151 | "bool_arr=(two_d>2)"
152 | ]
153 | },
154 | {
155 | "cell_type": "code",
156 | "execution_count": 10,
157 | "metadata": {},
158 | "outputs": [
159 | {
160 | "data": {
161 | "text/plain": [
162 | "array([[False, False, True],\n",
163 | " [ True, True, True]])"
164 | ]
165 | },
166 | "execution_count": 10,
167 | "metadata": {},
168 | "output_type": "execute_result"
169 | }
170 | ],
171 | "source": [
172 | "bool_arr"
173 | ]
174 | },
175 | {
176 | "cell_type": "code",
177 | "execution_count": 11,
178 | "metadata": {
179 | "collapsed": true
180 | },
181 | "outputs": [],
182 | "source": [
183 | "#condition in an array\n",
184 | "cond_arr=[i for i in one_d if i >1]"
185 | ]
186 | },
187 | {
188 | "cell_type": "code",
189 | "execution_count": 12,
190 | "metadata": {},
191 | "outputs": [
192 | {
193 | "data": {
194 | "text/plain": [
195 | "[2, 3]"
196 | ]
197 | },
198 | "execution_count": 12,
199 | "metadata": {},
200 | "output_type": "execute_result"
201 | }
202 | ],
203 | "source": [
204 | "cond_arr"
205 | ]
206 | },
207 | {
208 | "cell_type": "code",
209 | "execution_count": 13,
210 | "metadata": {
211 | "collapsed": true
212 | },
213 | "outputs": [],
214 | "source": [
215 | "#replacing values with some other values according to condition\n",
216 | "two_d[bool_arr]=20"
217 | ]
218 | },
219 | {
220 | "cell_type": "code",
221 | "execution_count": 14,
222 | "metadata": {},
223 | "outputs": [
224 | {
225 | "data": {
226 | "text/plain": [
227 | "array([[ 1, 2, 20],\n",
228 | " [20, 20, 20]])"
229 | ]
230 | },
231 | "execution_count": 14,
232 | "metadata": {},
233 | "output_type": "execute_result"
234 | }
235 | ],
236 | "source": [
237 | "two_d"
238 | ]
239 | },
240 | {
241 | "cell_type": "code",
242 | "execution_count": 15,
243 | "metadata": {
244 | "collapsed": true
245 | },
246 | "outputs": [],
247 | "source": [
248 | "#replacing different values"
249 | ]
250 | },
251 | {
252 | "cell_type": "code",
253 | "execution_count": 16,
254 | "metadata": {
255 | "collapsed": true
256 | },
257 | "outputs": [],
258 | "source": [
259 | "rep_array=np.where(two_d==20,5,10)"
260 | ]
261 | },
262 | {
263 | "cell_type": "code",
264 | "execution_count": 17,
265 | "metadata": {},
266 | "outputs": [
267 | {
268 | "data": {
269 | "text/plain": [
270 | "array([[10, 10, 5],\n",
271 | " [ 5, 5, 5]])"
272 | ]
273 | },
274 | "execution_count": 17,
275 | "metadata": {},
276 | "output_type": "execute_result"
277 | }
278 | ],
279 | "source": [
280 | "rep_array"
281 | ]
282 | },
283 | {
284 | "cell_type": "code",
285 | "execution_count": 18,
286 | "metadata": {
287 | "collapsed": true
288 | },
289 | "outputs": [],
290 | "source": [
291 | "#reshaping array\n",
292 | "res_array=np.reshape(rep_array,(3,2))"
293 | ]
294 | },
295 | {
296 | "cell_type": "code",
297 | "execution_count": 19,
298 | "metadata": {},
299 | "outputs": [
300 | {
301 | "data": {
302 | "text/plain": [
303 | "array([[10, 10],\n",
304 | " [ 5, 5],\n",
305 | " [ 5, 5]])"
306 | ]
307 | },
308 | "execution_count": 19,
309 | "metadata": {},
310 | "output_type": "execute_result"
311 | }
312 | ],
313 | "source": [
314 | "res_array"
315 | ]
316 | },
317 | {
318 | "cell_type": "code",
319 | "execution_count": 20,
320 | "metadata": {
321 | "collapsed": true
322 | },
323 | "outputs": [],
324 | "source": [
325 | "#vertical stacking\n",
326 | "a=np.array([1,2,3])"
327 | ]
328 | },
329 | {
330 | "cell_type": "code",
331 | "execution_count": 21,
332 | "metadata": {
333 | "collapsed": true
334 | },
335 | "outputs": [],
336 | "source": [
337 | "b=np.array([4,5,6])"
338 | ]
339 | },
340 | {
341 | "cell_type": "code",
342 | "execution_count": 22,
343 | "metadata": {
344 | "collapsed": true
345 | },
346 | "outputs": [],
347 | "source": [
348 | "ver_stack=np.vstack((a,b))"
349 | ]
350 | },
351 | {
352 | "cell_type": "code",
353 | "execution_count": 23,
354 | "metadata": {
355 | "collapsed": true
356 | },
357 | "outputs": [],
358 | "source": [
359 | "#horizontal stacking\n",
360 | "how_stack=np.hstack((a,b))"
361 | ]
362 | },
363 | {
364 | "cell_type": "code",
365 | "execution_count": 24,
366 | "metadata": {},
367 | "outputs": [
368 | {
369 | "data": {
370 | "text/plain": [
371 | "array([1, 2, 3, 4, 5, 6])"
372 | ]
373 | },
374 | "execution_count": 24,
375 | "metadata": {},
376 | "output_type": "execute_result"
377 | }
378 | ],
379 | "source": [
380 | "how_stack"
381 | ]
382 | },
383 | {
384 | "cell_type": "code",
385 | "execution_count": 25,
386 | "metadata": {
387 | "collapsed": true
388 | },
389 | "outputs": [],
390 | "source": [
391 | "#generate custom sequences \n",
392 | "seq=np.arange(10,20)"
393 | ]
394 | },
395 | {
396 | "cell_type": "code",
397 | "execution_count": 26,
398 | "metadata": {},
399 | "outputs": [
400 | {
401 | "data": {
402 | "text/plain": [
403 | "array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])"
404 | ]
405 | },
406 | "execution_count": 26,
407 | "metadata": {},
408 | "output_type": "execute_result"
409 | }
410 | ],
411 | "source": [
412 | "seq"
413 | ]
414 | },
415 | {
416 | "cell_type": "code",
417 | "execution_count": null,
418 | "metadata": {
419 | "collapsed": true
420 | },
421 | "outputs": [],
422 | "source": []
423 | }
424 | ],
425 | "metadata": {
426 | "kernelspec": {
427 | "display_name": "Python 3",
428 | "language": "python",
429 | "name": "python3"
430 | },
431 | "language_info": {
432 | "codemirror_mode": {
433 | "name": "ipython",
434 | "version": 3
435 | },
436 | "file_extension": ".py",
437 | "mimetype": "text/x-python",
438 | "name": "python",
439 | "nbconvert_exporter": "python",
440 | "pygments_lexer": "ipython3",
441 | "version": "3.6.8"
442 | }
443 | },
444 | "nbformat": 4,
445 | "nbformat_minor": 2
446 | }
447 |
--------------------------------------------------------------------------------
/numpy/Day4.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Numpy
\n",
8 | "\n",
9 | "## Questions\n",
10 | "\n",
11 | "11. How to get the common items between two python numpy arrays?\n",
12 | "\n",
13 | "12. How to remove from one array those items that exist in another?\n",
14 | "\n",
15 | "13. How to get the positions where elements of two arrays match?\n",
16 | "\n",
17 | "14. How to extract all numbers between a given range from a numpy array?\n",
18 | "\n",
19 | "15. How to make a python function that handles scalars to work on numpy arrays?\n",
20 | "\n",
21 | "16. How to swap two columns in a 2d numpy array?\n",
22 | "\n",
23 | "17. How to swap two rows in a 2d numpy array?\n",
24 | "\n",
25 | "18. How to reverse the rows of a 2D array?\n",
26 | "\n",
27 | "19. How to reverse the columns of a 2D array?\n",
28 | "\n",
29 | "20. How to create a 2D array containing random floats between 5 and 10?"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": 62,
35 | "metadata": {
36 | "collapsed": true
37 | },
38 | "outputs": [],
39 | "source": [
40 | "import numpy as np"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": 63,
46 | "metadata": {
47 | "collapsed": true
48 | },
49 | "outputs": [],
50 | "source": [
51 | "#1\n",
52 | "a=np.array([1,2,3,4])\n",
53 | "b=np.array([4,3,5,6])"
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "execution_count": 64,
59 | "metadata": {},
60 | "outputs": [
61 | {
62 | "data": {
63 | "text/plain": [
64 | "array([3, 4])"
65 | ]
66 | },
67 | "execution_count": 64,
68 | "metadata": {},
69 | "output_type": "execute_result"
70 | }
71 | ],
72 | "source": [
73 | "common=np.intersect1d(a,b)\n",
74 | "common"
75 | ]
76 | },
77 | {
78 | "cell_type": "code",
79 | "execution_count": 65,
80 | "metadata": {},
81 | "outputs": [],
82 | "source": [
83 | "#2\n",
84 | "rem_common=np.setdiff1d(a,common)"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": 66,
90 | "metadata": {},
91 | "outputs": [
92 | {
93 | "data": {
94 | "text/plain": [
95 | "array([1, 2])"
96 | ]
97 | },
98 | "execution_count": 66,
99 | "metadata": {},
100 | "output_type": "execute_result"
101 | }
102 | ],
103 | "source": [
104 | "rem_common"
105 | ]
106 | },
107 | {
108 | "cell_type": "code",
109 | "execution_count": 67,
110 | "metadata": {},
111 | "outputs": [],
112 | "source": [
113 | "#3\n",
114 | "common=np.intersect1d(a,b,return_indices=True)"
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": 68,
120 | "metadata": {},
121 | "outputs": [
122 | {
123 | "data": {
124 | "text/plain": [
125 | "(array([2, 3]), array([1, 0]))"
126 | ]
127 | },
128 | "execution_count": 68,
129 | "metadata": {},
130 | "output_type": "execute_result"
131 | }
132 | ],
133 | "source": [
134 | "common[1:3]"
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": 69,
140 | "metadata": {},
141 | "outputs": [],
142 | "source": [
143 | "#4 extraction\n",
144 | "ext=np.where(a>2)"
145 | ]
146 | },
147 | {
148 | "cell_type": "code",
149 | "execution_count": 70,
150 | "metadata": {},
151 | "outputs": [
152 | {
153 | "data": {
154 | "text/plain": [
155 | "(array([2, 3]),)"
156 | ]
157 | },
158 | "execution_count": 70,
159 | "metadata": {},
160 | "output_type": "execute_result"
161 | }
162 | ],
163 | "source": [
164 | "ext"
165 | ]
166 | },
167 | {
168 | "cell_type": "code",
169 | "execution_count": 71,
170 | "metadata": {},
171 | "outputs": [
172 | {
173 | "data": {
174 | "text/plain": [
175 | "array(25)"
176 | ]
177 | },
178 | "execution_count": 71,
179 | "metadata": {},
180 | "output_type": "execute_result"
181 | }
182 | ],
183 | "source": [
184 | "#5\n",
185 | "sca=25\n",
186 | "np.asarray(sca)"
187 | ]
188 | },
189 | {
190 | "cell_type": "code",
191 | "execution_count": 72,
192 | "metadata": {},
193 | "outputs": [],
194 | "source": [
195 | "# swapping 2 columns\n",
196 | "a=np.arange(10,20)\n",
197 | "a=np.reshape(a,(5,2))"
198 | ]
199 | },
200 | {
201 | "cell_type": "code",
202 | "execution_count": 73,
203 | "metadata": {},
204 | "outputs": [
205 | {
206 | "data": {
207 | "text/plain": [
208 | "array([[10, 11],\n",
209 | " [12, 13],\n",
210 | " [14, 15],\n",
211 | " [16, 17],\n",
212 | " [18, 19]])"
213 | ]
214 | },
215 | "execution_count": 73,
216 | "metadata": {},
217 | "output_type": "execute_result"
218 | }
219 | ],
220 | "source": [
221 | "a"
222 | ]
223 | },
224 | {
225 | "cell_type": "code",
226 | "execution_count": 74,
227 | "metadata": {},
228 | "outputs": [],
229 | "source": [
230 | "a[:,[0,1]]=a[:,[1,0]]"
231 | ]
232 | },
233 | {
234 | "cell_type": "code",
235 | "execution_count": 75,
236 | "metadata": {},
237 | "outputs": [
238 | {
239 | "data": {
240 | "text/plain": [
241 | "array([[11, 10],\n",
242 | " [13, 12],\n",
243 | " [15, 14],\n",
244 | " [17, 16],\n",
245 | " [19, 18]])"
246 | ]
247 | },
248 | "execution_count": 75,
249 | "metadata": {},
250 | "output_type": "execute_result"
251 | }
252 | ],
253 | "source": [
254 | "a"
255 | ]
256 | },
257 | {
258 | "cell_type": "code",
259 | "execution_count": 76,
260 | "metadata": {
261 | "collapsed": true
262 | },
263 | "outputs": [],
264 | "source": [
265 | "#swapping rows\n",
266 | "a[[0,1],:]=a[[1,0],:]"
267 | ]
268 | },
269 | {
270 | "cell_type": "code",
271 | "execution_count": 77,
272 | "metadata": {},
273 | "outputs": [
274 | {
275 | "data": {
276 | "text/plain": [
277 | "array([[13, 12],\n",
278 | " [11, 10],\n",
279 | " [15, 14],\n",
280 | " [17, 16],\n",
281 | " [19, 18]])"
282 | ]
283 | },
284 | "execution_count": 77,
285 | "metadata": {},
286 | "output_type": "execute_result"
287 | }
288 | ],
289 | "source": [
290 | "a"
291 | ]
292 | },
293 | {
294 | "cell_type": "code",
295 | "execution_count": 78,
296 | "metadata": {},
297 | "outputs": [
298 | {
299 | "data": {
300 | "text/plain": [
301 | "array([12, 13])"
302 | ]
303 | },
304 | "execution_count": 78,
305 | "metadata": {},
306 | "output_type": "execute_result"
307 | }
308 | ],
309 | "source": [
310 | "#8 flipping or reversing columns\n",
311 | "np.fliplr(a)[0]"
312 | ]
313 | },
314 | {
315 | "cell_type": "code",
316 | "execution_count": 80,
317 | "metadata": {},
318 | "outputs": [
319 | {
320 | "data": {
321 | "text/plain": [
322 | "array([19, 18])"
323 | ]
324 | },
325 | "execution_count": 80,
326 | "metadata": {},
327 | "output_type": "execute_result"
328 | }
329 | ],
330 | "source": [
331 | "#9 flipping or reversing rows\n",
332 | "np.flipud(a)[0]"
333 | ]
334 | },
335 | {
336 | "cell_type": "code",
337 | "execution_count": 81,
338 | "metadata": {},
339 | "outputs": [
340 | {
341 | "data": {
342 | "text/plain": [
343 | "array([[13, 12],\n",
344 | " [11, 10],\n",
345 | " [15, 14],\n",
346 | " [17, 16],\n",
347 | " [19, 18]])"
348 | ]
349 | },
350 | "execution_count": 81,
351 | "metadata": {},
352 | "output_type": "execute_result"
353 | }
354 | ],
355 | "source": [
356 | "a"
357 | ]
358 | },
359 | {
360 | "cell_type": "code",
361 | "execution_count": 82,
362 | "metadata": {
363 | "collapsed": true
364 | },
365 | "outputs": [],
366 | "source": [
367 | "#create random floats\n",
368 | "\n",
369 | "a=np.random.uniform(5,10,10)"
370 | ]
371 | },
372 | {
373 | "cell_type": "code",
374 | "execution_count": 83,
375 | "metadata": {},
376 | "outputs": [
377 | {
378 | "data": {
379 | "text/plain": [
380 | "array([9.69224612, 6.87253239, 7.0710452 , 6.60147262, 7.52384422,\n",
381 | " 8.02138016, 7.57824725, 6.45647798, 8.39363667, 7.64057668])"
382 | ]
383 | },
384 | "execution_count": 83,
385 | "metadata": {},
386 | "output_type": "execute_result"
387 | }
388 | ],
389 | "source": [
390 | "a"
391 | ]
392 | },
393 | {
394 | "cell_type": "code",
395 | "execution_count": null,
396 | "metadata": {
397 | "collapsed": true
398 | },
399 | "outputs": [],
400 | "source": []
401 | }
402 | ],
403 | "metadata": {
404 | "kernelspec": {
405 | "display_name": "Python 3",
406 | "language": "python",
407 | "name": "python3"
408 | },
409 | "language_info": {
410 | "codemirror_mode": {
411 | "name": "ipython",
412 | "version": 3
413 | },
414 | "file_extension": ".py",
415 | "mimetype": "text/x-python",
416 | "name": "python",
417 | "nbconvert_exporter": "python",
418 | "pygments_lexer": "ipython3",
419 | "version": "3.6.8"
420 | }
421 | },
422 | "nbformat": 4,
423 | "nbformat_minor": 2
424 | }
425 |
--------------------------------------------------------------------------------
/numpy/Day5.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Numpy
\n",
8 | "\n",
9 | "## Questions \n",
10 | "\n",
11 | "21. How to print only 3 decimal places in python numpy array?\n",
12 | "22. How to pretty print a numpy array by suppressing the scientific notation (like 1e10)?\n",
13 | "23. How to limit the number of items printed in output of numpy array?\n",
14 | "24. How to print the full numpy array without truncating\n",
15 | "25. How to import a dataset with numbers and texts keeping the text intact in python numpy?\n",
16 | "26. How to extract a particular column from 1D array of tuples?\n",
17 | "27. How to convert a 1d array of tuples to a 2d numpy array?\n",
18 | "28. How to compute the mean, median, standard deviation of a numpy array?\n",
19 | "29. How to normalize an array so the values range exactly between 0 and 1?\n",
20 | "30. How to compute the softmax score?"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": 1,
26 | "metadata": {},
27 | "outputs": [],
28 | "source": [
29 | "import numpy as np\n",
30 | "a=np.array([1.9875,3.6328,44.27382,10*np.exp(10),1.23,324,545,23,12,43,35])"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 2,
36 | "metadata": {},
37 | "outputs": [
38 | {
39 | "data": {
40 | "text/plain": [
41 | "array([1.98750000e+00, 3.63280000e+00, 4.42738200e+01, 2.20264658e+05,\n",
42 | " 1.23000000e+00, 3.24000000e+02, 5.45000000e+02, 2.30000000e+01,\n",
43 | " 1.20000000e+01, 4.30000000e+01, 3.50000000e+01])"
44 | ]
45 | },
46 | "execution_count": 2,
47 | "metadata": {},
48 | "output_type": "execute_result"
49 | }
50 | ],
51 | "source": [
52 | "a"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": 3,
58 | "metadata": {
59 | "collapsed": true
60 | },
61 | "outputs": [],
62 | "source": [
63 | "#1\n",
64 | "np.set_printoptions(3)"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": 4,
70 | "metadata": {},
71 | "outputs": [
72 | {
73 | "data": {
74 | "text/plain": [
75 | "array([1.988e+00, 3.633e+00, 4.427e+01, 2.203e+05, 1.230e+00, 3.240e+02,\n",
76 | " 5.450e+02, 2.300e+01, 1.200e+01, 4.300e+01, 3.500e+01])"
77 | ]
78 | },
79 | "execution_count": 4,
80 | "metadata": {},
81 | "output_type": "execute_result"
82 | }
83 | ],
84 | "source": [
85 | "a"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": 5,
91 | "metadata": {},
92 | "outputs": [],
93 | "source": [
94 | "#2\n",
95 | "np.set_printoptions(suppress=True)"
96 | ]
97 | },
98 | {
99 | "cell_type": "code",
100 | "execution_count": 6,
101 | "metadata": {},
102 | "outputs": [
103 | {
104 | "data": {
105 | "text/plain": [
106 | "array([ 1.988, 3.633, 44.274, 220264.658, 1.23 ,\n",
107 | " 324. , 545. , 23. , 12. , 43. ,\n",
108 | " 35. ])"
109 | ]
110 | },
111 | "execution_count": 6,
112 | "metadata": {},
113 | "output_type": "execute_result"
114 | }
115 | ],
116 | "source": [
117 | "a"
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "execution_count": 7,
123 | "metadata": {},
124 | "outputs": [],
125 | "source": [
126 | "#3\n",
127 | "np.set_printoptions(threshold=2)"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "execution_count": 8,
133 | "metadata": {},
134 | "outputs": [
135 | {
136 | "data": {
137 | "text/plain": [
138 | "array([ 1.988, 3.633, 44.274, ..., 12. , 43. , 35. ])"
139 | ]
140 | },
141 | "execution_count": 8,
142 | "metadata": {},
143 | "output_type": "execute_result"
144 | }
145 | ],
146 | "source": [
147 | "a"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": 9,
153 | "metadata": {
154 | "collapsed": true
155 | },
156 | "outputs": [],
157 | "source": [
158 | "#4\n",
159 | "np.set_printoptions(threshold=np.inf)"
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": 10,
165 | "metadata": {},
166 | "outputs": [
167 | {
168 | "data": {
169 | "text/plain": [
170 | "array([ 1.988, 3.633, 44.274, 220264.658, 1.23 ,\n",
171 | " 324. , 545. , 23. , 12. , 43. ,\n",
172 | " 35. ])"
173 | ]
174 | },
175 | "execution_count": 10,
176 | "metadata": {},
177 | "output_type": "execute_result"
178 | }
179 | ],
180 | "source": [
181 | "a"
182 | ]
183 | },
184 | {
185 | "cell_type": "code",
186 | "execution_count": 11,
187 | "metadata": {},
188 | "outputs": [
189 | {
190 | "ename": "NameError",
191 | "evalue": "name 'filepath' is not defined",
192 | "output_type": "error",
193 | "traceback": [
194 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
195 | "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
196 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m#5\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloadtxt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfname\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
197 | "\u001b[0;31mNameError\u001b[0m: name 'filepath' is not defined"
198 | ]
199 | }
200 | ],
201 | "source": [
202 | "#5\n",
203 | "df=np.loadtxt(fname = {filepath}) "
204 | ]
205 | },
206 | {
207 | "cell_type": "code",
208 | "execution_count": 12,
209 | "metadata": {
210 | "collapsed": true
211 | },
212 | "outputs": [],
213 | "source": [
214 | "#6\n",
215 | "b=np.array([(1,2,3),(4,5,6),(7,8,9)])"
216 | ]
217 | },
218 | {
219 | "cell_type": "code",
220 | "execution_count": 13,
221 | "metadata": {},
222 | "outputs": [
223 | {
224 | "data": {
225 | "text/plain": [
226 | "array([1, 4, 7])"
227 | ]
228 | },
229 | "execution_count": 13,
230 | "metadata": {},
231 | "output_type": "execute_result"
232 | }
233 | ],
234 | "source": [
235 | "#extracting first column\n",
236 | "b[:,0]"
237 | ]
238 | },
239 | {
240 | "cell_type": "code",
241 | "execution_count": 14,
242 | "metadata": {},
243 | "outputs": [
244 | {
245 | "data": {
246 | "text/plain": [
247 | "array([[1, 2, 3],\n",
248 | " [4, 5, 6]])"
249 | ]
250 | },
251 | "execution_count": 14,
252 | "metadata": {},
253 | "output_type": "execute_result"
254 | }
255 | ],
256 | "source": [
257 | "#7\n",
258 | "c=[(1,2,3),(4,5,6)]\n",
259 | "np.array(c)"
260 | ]
261 | },
262 | {
263 | "cell_type": "code",
264 | "execution_count": 15,
265 | "metadata": {
266 | "collapsed": true
267 | },
268 | "outputs": [],
269 | "source": [
270 | "#8\n",
271 | "mean_a=np.mean(a)\n",
272 | "median_a=np.median(a)\n",
273 | "std_a=np.std(a)"
274 | ]
275 | },
276 | {
277 | "cell_type": "code",
278 | "execution_count": 16,
279 | "metadata": {},
280 | "outputs": [
281 | {
282 | "data": {
283 | "text/plain": [
284 | "20117.98018800611"
285 | ]
286 | },
287 | "execution_count": 16,
288 | "metadata": {},
289 | "output_type": "execute_result"
290 | }
291 | ],
292 | "source": [
293 | "mean_a"
294 | ]
295 | },
296 | {
297 | "cell_type": "code",
298 | "execution_count": 17,
299 | "metadata": {},
300 | "outputs": [
301 | {
302 | "data": {
303 | "text/plain": [
304 | "35.0"
305 | ]
306 | },
307 | "execution_count": 17,
308 | "metadata": {},
309 | "output_type": "execute_result"
310 | }
311 | ],
312 | "source": [
313 | "median_a"
314 | ]
315 | },
316 | {
317 | "cell_type": "code",
318 | "execution_count": 18,
319 | "metadata": {},
320 | "outputs": [
321 | {
322 | "data": {
323 | "text/plain": [
324 | "63292.15294785072"
325 | ]
326 | },
327 | "execution_count": 18,
328 | "metadata": {},
329 | "output_type": "execute_result"
330 | }
331 | ],
332 | "source": [
333 | "std_a"
334 | ]
335 | },
336 | {
337 | "cell_type": "code",
338 | "execution_count": 19,
339 | "metadata": {
340 | "collapsed": true
341 | },
342 | "outputs": [],
343 | "source": [
344 | "#9\n",
345 | "norm_a=(a-np.min(a))/(np.max(a)-np.min(a))"
346 | ]
347 | },
348 | {
349 | "cell_type": "code",
350 | "execution_count": 20,
351 | "metadata": {},
352 | "outputs": [
353 | {
354 | "data": {
355 | "text/plain": [
356 | "array([0. , 0. , 0. , 1. , 0. , 0.001, 0.002, 0. , 0. ,\n",
357 | " 0. , 0. ])"
358 | ]
359 | },
360 | "execution_count": 20,
361 | "metadata": {},
362 | "output_type": "execute_result"
363 | }
364 | ],
365 | "source": [
366 | "norm_a"
367 | ]
368 | },
369 | {
370 | "cell_type": "code",
371 | "execution_count": 21,
372 | "metadata": {},
373 | "outputs": [
374 | {
375 | "name": "stderr",
376 | "output_type": "stream",
377 | "text": [
378 | "/home/shashank/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:2: RuntimeWarning: overflow encountered in exp\n",
379 | " \n",
380 | "/home/shashank/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:2: RuntimeWarning: invalid value encountered in true_divide\n",
381 | " \n"
382 | ]
383 | }
384 | ],
385 | "source": [
386 | "#10\n",
387 | "soft_a=np.exp(a) / np.sum(np.exp(a), axis=0)"
388 | ]
389 | },
390 | {
391 | "cell_type": "code",
392 | "execution_count": 22,
393 | "metadata": {},
394 | "outputs": [
395 | {
396 | "data": {
397 | "text/plain": [
398 | "array([ 0., 0., 0., nan, 0., 0., 0., 0., 0., 0., 0.])"
399 | ]
400 | },
401 | "execution_count": 22,
402 | "metadata": {},
403 | "output_type": "execute_result"
404 | }
405 | ],
406 | "source": [
407 | "soft_a"
408 | ]
409 | },
410 | {
411 | "cell_type": "code",
412 | "execution_count": null,
413 | "metadata": {},
414 | "outputs": [],
415 | "source": []
416 | },
417 | {
418 | "cell_type": "code",
419 | "execution_count": null,
420 | "metadata": {
421 | "collapsed": true
422 | },
423 | "outputs": [],
424 | "source": []
425 | },
426 | {
427 | "cell_type": "code",
428 | "execution_count": null,
429 | "metadata": {},
430 | "outputs": [],
431 | "source": []
432 | },
433 | {
434 | "cell_type": "code",
435 | "execution_count": null,
436 | "metadata": {
437 | "collapsed": true
438 | },
439 | "outputs": [],
440 | "source": []
441 | }
442 | ],
443 | "metadata": {
444 | "kernelspec": {
445 | "display_name": "Python 3",
446 | "language": "python",
447 | "name": "python3"
448 | },
449 | "language_info": {
450 | "codemirror_mode": {
451 | "name": "ipython",
452 | "version": 3
453 | },
454 | "file_extension": ".py",
455 | "mimetype": "text/x-python",
456 | "name": "python",
457 | "nbconvert_exporter": "python",
458 | "pygments_lexer": "ipython3",
459 | "version": "3.6.8"
460 | }
461 | },
462 | "nbformat": 4,
463 | "nbformat_minor": 2
464 | }
465 |
--------------------------------------------------------------------------------
/numpy/Day8.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | " Numpy
\n",
8 | "\n",
9 | "## Questions\n",
10 | "\n",
11 | "66. How to convert numpy's datetime64 object to datetime's datetime object?\n",
12 | "67. How to compute the moving average of a numpy array?\n",
13 | "68. How to create a numpy array sequence given only the starting point, length and the step?\n",
14 | "69. How to fill in missing dates in an irregular series of numpy dates?\n",
15 | "70. How to create strides from a given 1D array?"
16 | ]
17 | },
18 | {
19 | "cell_type": "code",
20 | "execution_count": 3,
21 | "metadata": {
22 | "collapsed": true
23 | },
24 | "outputs": [],
25 | "source": [
26 | "import numpy as np\n",
27 | "from datetime import datetime"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": 4,
33 | "metadata": {},
34 | "outputs": [
35 | {
36 | "data": {
37 | "text/plain": [
38 | "datetime.datetime(2019, 7, 16, 23, 11, 51, 25921)"
39 | ]
40 | },
41 | "execution_count": 4,
42 | "metadata": {},
43 | "output_type": "execute_result"
44 | }
45 | ],
46 | "source": [
47 | "#1\n",
48 | "dt64 = np.datetime64(datetime.now())\n",
49 | "dt64.tolist()"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": 10,
55 | "metadata": {},
56 | "outputs": [],
57 | "source": [
58 | "#2\n",
59 | "a=np.random.randint(10,size=10)"
60 | ]
61 | },
62 | {
63 | "cell_type": "code",
64 | "execution_count": 12,
65 | "metadata": {},
66 | "outputs": [
67 | {
68 | "data": {
69 | "text/plain": [
70 | "array([4.33333333, 5. , 3.66666667, 3.66666667, 1.33333333,\n",
71 | " 1.33333333, 2.33333333, 5.33333333])"
72 | ]
73 | },
74 | "execution_count": 12,
75 | "metadata": {},
76 | "output_type": "execute_result"
77 | }
78 | ],
79 | "source": [
80 | "np.convolve(a, np.ones(3)/3, mode='valid')"
81 | ]
82 | },
83 | {
84 | "cell_type": "code",
85 | "execution_count": 14,
86 | "metadata": {},
87 | "outputs": [],
88 | "source": [
89 | "#3\n",
90 | "b=np.arange(1,10,2)"
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "execution_count": 15,
96 | "metadata": {},
97 | "outputs": [
98 | {
99 | "data": {
100 | "text/plain": [
101 | "array([1, 3, 5, 7, 9])"
102 | ]
103 | },
104 | "execution_count": 15,
105 | "metadata": {},
106 | "output_type": "execute_result"
107 | }
108 | ],
109 | "source": [
110 | "b"
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "execution_count": 16,
116 | "metadata": {},
117 | "outputs": [
118 | {
119 | "name": "stdout",
120 | "output_type": "stream",
121 | "text": [
122 | "['2018-02-01' '2018-02-03' '2018-02-05' '2018-02-07' '2018-02-09'\n",
123 | " '2018-02-11' '2018-02-13' '2018-02-15' '2018-02-17' '2018-02-19'\n",
124 | " '2018-02-21' '2018-02-23']\n"
125 | ]
126 | }
127 | ],
128 | "source": [
129 | "#4\n",
130 | "dates = np.arange(np.datetime64('2018-02-01'), np.datetime64('2018-02-25'), 2)\n",
131 | "print(dates)\n",
132 | "\n",
133 | "# Solution ---------------\n",
134 | "filled_in = np.array([np.arange(date, (date+d)) for date, d in zip(dates, np.diff(dates))]).reshape(-1)"
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": 17,
140 | "metadata": {},
141 | "outputs": [
142 | {
143 | "data": {
144 | "text/plain": [
145 | "array(['2018-02-01', '2018-02-02', '2018-02-03', '2018-02-04',\n",
146 | " '2018-02-05', '2018-02-06', '2018-02-07', '2018-02-08',\n",
147 | " '2018-02-09', '2018-02-10', '2018-02-11', '2018-02-12',\n",
148 | " '2018-02-13', '2018-02-14', '2018-02-15', '2018-02-16',\n",
149 | " '2018-02-17', '2018-02-18', '2018-02-19', '2018-02-20',\n",
150 | " '2018-02-21', '2018-02-22'], dtype='datetime64[D]')"
151 | ]
152 | },
153 | "execution_count": 17,
154 | "metadata": {},
155 | "output_type": "execute_result"
156 | }
157 | ],
158 | "source": [
159 | "filled_in"
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": 18,
165 | "metadata": {},
166 | "outputs": [
167 | {
168 | "name": "stdout",
169 | "output_type": "stream",
170 | "text": [
171 | "[[ 0 1 2 3]\n",
172 | " [ 2 3 4 5]\n",
173 | " [ 4 5 6 7]\n",
174 | " [ 6 7 8 9]\n",
175 | " [ 8 9 10 11]\n",
176 | " [10 11 12 13]]\n"
177 | ]
178 | }
179 | ],
180 | "source": [
181 | "#5\n",
182 | "def gen_strides(a, stride_len=5, window_len=5):\n",
183 | " n_strides = ((a.size-window_len)//stride_len) + 1\n",
184 | " return np.array([a[s:(s+window_len)] for s in np.arange(0, n_strides*stride_len, stride_len)])\n",
185 | "\n",
186 | "print(gen_strides(np.arange(15), stride_len=2, window_len=4))"
187 | ]
188 | },
189 | {
190 | "cell_type": "code",
191 | "execution_count": null,
192 | "metadata": {
193 | "collapsed": true
194 | },
195 | "outputs": [],
196 | "source": []
197 | }
198 | ],
199 | "metadata": {
200 | "kernelspec": {
201 | "display_name": "Python 3",
202 | "language": "python",
203 | "name": "python3"
204 | },
205 | "language_info": {
206 | "codemirror_mode": {
207 | "name": "ipython",
208 | "version": 3
209 | },
210 | "file_extension": ".py",
211 | "mimetype": "text/x-python",
212 | "name": "python",
213 | "nbconvert_exporter": "python",
214 | "pygments_lexer": "ipython3",
215 | "version": "3.6.8"
216 | }
217 | },
218 | "nbformat": 4,
219 | "nbformat_minor": 2
220 | }
221 |
--------------------------------------------------------------------------------
/numpy/archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data:
--------------------------------------------------------------------------------
1 | 5.1,3.5,1.4,0.2,Iris-setosa
2 | 4.9,3.0,1.4,0.2,Iris-setosa
3 | 4.7,3.2,1.3,0.2,Iris-setosa
4 | 4.6,3.1,1.5,0.2,Iris-setosa
5 | 5.0,3.6,1.4,0.2,Iris-setosa
6 | 5.4,3.9,1.7,0.4,Iris-setosa
7 | 4.6,3.4,1.4,0.3,Iris-setosa
8 | 5.0,3.4,1.5,0.2,Iris-setosa
9 | 4.4,2.9,1.4,0.2,Iris-setosa
10 | 4.9,3.1,1.5,0.1,Iris-setosa
11 | 5.4,3.7,1.5,0.2,Iris-setosa
12 | 4.8,3.4,1.6,0.2,Iris-setosa
13 | 4.8,3.0,1.4,0.1,Iris-setosa
14 | 4.3,3.0,1.1,0.1,Iris-setosa
15 | 5.8,4.0,1.2,0.2,Iris-setosa
16 | 5.7,4.4,1.5,0.4,Iris-setosa
17 | 5.4,3.9,1.3,0.4,Iris-setosa
18 | 5.1,3.5,1.4,0.3,Iris-setosa
19 | 5.7,3.8,1.7,0.3,Iris-setosa
20 | 5.1,3.8,1.5,0.3,Iris-setosa
21 | 5.4,3.4,1.7,0.2,Iris-setosa
22 | 5.1,3.7,1.5,0.4,Iris-setosa
23 | 4.6,3.6,1.0,0.2,Iris-setosa
24 | 5.1,3.3,1.7,0.5,Iris-setosa
25 | 4.8,3.4,1.9,0.2,Iris-setosa
26 | 5.0,3.0,1.6,0.2,Iris-setosa
27 | 5.0,3.4,1.6,0.4,Iris-setosa
28 | 5.2,3.5,1.5,0.2,Iris-setosa
29 | 5.2,3.4,1.4,0.2,Iris-setosa
30 | 4.7,3.2,1.6,0.2,Iris-setosa
31 | 4.8,3.1,1.6,0.2,Iris-setosa
32 | 5.4,3.4,1.5,0.4,Iris-setosa
33 | 5.2,4.1,1.5,0.1,Iris-setosa
34 | 5.5,4.2,1.4,0.2,Iris-setosa
35 | 4.9,3.1,1.5,0.1,Iris-setosa
36 | 5.0,3.2,1.2,0.2,Iris-setosa
37 | 5.5,3.5,1.3,0.2,Iris-setosa
38 | 4.9,3.1,1.5,0.1,Iris-setosa
39 | 4.4,3.0,1.3,0.2,Iris-setosa
40 | 5.1,3.4,1.5,0.2,Iris-setosa
41 | 5.0,3.5,1.3,0.3,Iris-setosa
42 | 4.5,2.3,1.3,0.3,Iris-setosa
43 | 4.4,3.2,1.3,0.2,Iris-setosa
44 | 5.0,3.5,1.6,0.6,Iris-setosa
45 | 5.1,3.8,1.9,0.4,Iris-setosa
46 | 4.8,3.0,1.4,0.3,Iris-setosa
47 | 5.1,3.8,1.6,0.2,Iris-setosa
48 | 4.6,3.2,1.4,0.2,Iris-setosa
49 | 5.3,3.7,1.5,0.2,Iris-setosa
50 | 5.0,3.3,1.4,0.2,Iris-setosa
51 | 7.0,3.2,4.7,1.4,Iris-versicolor
52 | 6.4,3.2,4.5,1.5,Iris-versicolor
53 | 6.9,3.1,4.9,1.5,Iris-versicolor
54 | 5.5,2.3,4.0,1.3,Iris-versicolor
55 | 6.5,2.8,4.6,1.5,Iris-versicolor
56 | 5.7,2.8,4.5,1.3,Iris-versicolor
57 | 6.3,3.3,4.7,1.6,Iris-versicolor
58 | 4.9,2.4,3.3,1.0,Iris-versicolor
59 | 6.6,2.9,4.6,1.3,Iris-versicolor
60 | 5.2,2.7,3.9,1.4,Iris-versicolor
61 | 5.0,2.0,3.5,1.0,Iris-versicolor
62 | 5.9,3.0,4.2,1.5,Iris-versicolor
63 | 6.0,2.2,4.0,1.0,Iris-versicolor
64 | 6.1,2.9,4.7,1.4,Iris-versicolor
65 | 5.6,2.9,3.6,1.3,Iris-versicolor
66 | 6.7,3.1,4.4,1.4,Iris-versicolor
67 | 5.6,3.0,4.5,1.5,Iris-versicolor
68 | 5.8,2.7,4.1,1.0,Iris-versicolor
69 | 6.2,2.2,4.5,1.5,Iris-versicolor
70 | 5.6,2.5,3.9,1.1,Iris-versicolor
71 | 5.9,3.2,4.8,1.8,Iris-versicolor
72 | 6.1,2.8,4.0,1.3,Iris-versicolor
73 | 6.3,2.5,4.9,1.5,Iris-versicolor
74 | 6.1,2.8,4.7,1.2,Iris-versicolor
75 | 6.4,2.9,4.3,1.3,Iris-versicolor
76 | 6.6,3.0,4.4,1.4,Iris-versicolor
77 | 6.8,2.8,4.8,1.4,Iris-versicolor
78 | 6.7,3.0,5.0,1.7,Iris-versicolor
79 | 6.0,2.9,4.5,1.5,Iris-versicolor
80 | 5.7,2.6,3.5,1.0,Iris-versicolor
81 | 5.5,2.4,3.8,1.1,Iris-versicolor
82 | 5.5,2.4,3.7,1.0,Iris-versicolor
83 | 5.8,2.7,3.9,1.2,Iris-versicolor
84 | 6.0,2.7,5.1,1.6,Iris-versicolor
85 | 5.4,3.0,4.5,1.5,Iris-versicolor
86 | 6.0,3.4,4.5,1.6,Iris-versicolor
87 | 6.7,3.1,4.7,1.5,Iris-versicolor
88 | 6.3,2.3,4.4,1.3,Iris-versicolor
89 | 5.6,3.0,4.1,1.3,Iris-versicolor
90 | 5.5,2.5,4.0,1.3,Iris-versicolor
91 | 5.5,2.6,4.4,1.2,Iris-versicolor
92 | 6.1,3.0,4.6,1.4,Iris-versicolor
93 | 5.8,2.6,4.0,1.2,Iris-versicolor
94 | 5.0,2.3,3.3,1.0,Iris-versicolor
95 | 5.6,2.7,4.2,1.3,Iris-versicolor
96 | 5.7,3.0,4.2,1.2,Iris-versicolor
97 | 5.7,2.9,4.2,1.3,Iris-versicolor
98 | 6.2,2.9,4.3,1.3,Iris-versicolor
99 | 5.1,2.5,3.0,1.1,Iris-versicolor
100 | 5.7,2.8,4.1,1.3,Iris-versicolor
101 | 6.3,3.3,6.0,2.5,Iris-virginica
102 | 5.8,2.7,5.1,1.9,Iris-virginica
103 | 7.1,3.0,5.9,2.1,Iris-virginica
104 | 6.3,2.9,5.6,1.8,Iris-virginica
105 | 6.5,3.0,5.8,2.2,Iris-virginica
106 | 7.6,3.0,6.6,2.1,Iris-virginica
107 | 4.9,2.5,4.5,1.7,Iris-virginica
108 | 7.3,2.9,6.3,1.8,Iris-virginica
109 | 6.7,2.5,5.8,1.8,Iris-virginica
110 | 7.2,3.6,6.1,2.5,Iris-virginica
111 | 6.5,3.2,5.1,2.0,Iris-virginica
112 | 6.4,2.7,5.3,1.9,Iris-virginica
113 | 6.8,3.0,5.5,2.1,Iris-virginica
114 | 5.7,2.5,5.0,2.0,Iris-virginica
115 | 5.8,2.8,5.1,2.4,Iris-virginica
116 | 6.4,3.2,5.3,2.3,Iris-virginica
117 | 6.5,3.0,5.5,1.8,Iris-virginica
118 | 7.7,3.8,6.7,2.2,Iris-virginica
119 | 7.7,2.6,6.9,2.3,Iris-virginica
120 | 6.0,2.2,5.0,1.5,Iris-virginica
121 | 6.9,3.2,5.7,2.3,Iris-virginica
122 | 5.6,2.8,4.9,2.0,Iris-virginica
123 | 7.7,2.8,6.7,2.0,Iris-virginica
124 | 6.3,2.7,4.9,1.8,Iris-virginica
125 | 6.7,3.3,5.7,2.1,Iris-virginica
126 | 7.2,3.2,6.0,1.8,Iris-virginica
127 | 6.2,2.8,4.8,1.8,Iris-virginica
128 | 6.1,3.0,4.9,1.8,Iris-virginica
129 | 6.4,2.8,5.6,2.1,Iris-virginica
130 | 7.2,3.0,5.8,1.6,Iris-virginica
131 | 7.4,2.8,6.1,1.9,Iris-virginica
132 | 7.9,3.8,6.4,2.0,Iris-virginica
133 | 6.4,2.8,5.6,2.2,Iris-virginica
134 | 6.3,2.8,5.1,1.5,Iris-virginica
135 | 6.1,2.6,5.6,1.4,Iris-virginica
136 | 7.7,3.0,6.1,2.3,Iris-virginica
137 | 6.3,3.4,5.6,2.4,Iris-virginica
138 | 6.4,3.1,5.5,1.8,Iris-virginica
139 | 6.0,3.0,4.8,1.8,Iris-virginica
140 | 6.9,3.1,5.4,2.1,Iris-virginica
141 | 6.7,3.1,5.6,2.4,Iris-virginica
142 | 6.9,3.1,5.1,2.3,Iris-virginica
143 | 5.8,2.7,5.1,1.9,Iris-virginica
144 | 6.8,3.2,5.9,2.3,Iris-virginica
145 | 6.7,3.3,5.7,2.5,Iris-virginica
146 | 6.7,3.0,5.2,2.3,Iris-virginica
147 | 6.3,2.5,5.0,1.9,Iris-virginica
148 | 6.5,3.0,5.2,2.0,Iris-virginica
149 | 6.2,3.4,5.4,2.3,Iris-virginica
150 | 5.9,3.0,5.1,1.8,Iris-virginica
151 |
152 |
--------------------------------------------------------------------------------
/output_based_questions/Day11.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | " OUTPUT BASED QUESTIONS
\n",
8 | "\n"
9 | ]
10 | },
11 | {
12 | "cell_type": "markdown",
13 | "metadata": {},
14 | "source": [
15 | "
"
16 | ]
17 | },
18 | {
19 | "cell_type": "code",
20 | "execution_count": 2,
21 | "metadata": {},
22 | "outputs": [
23 | {
24 | "name": "stdout",
25 | "output_type": "stream",
26 | "text": [
27 | "1\n"
28 | ]
29 | }
30 | ],
31 | "source": [
32 | "#1\n",
33 | "a={(1,2):1,(2,3):2}\n",
34 | "print(a[1,2])"
35 | ]
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": 3,
40 | "metadata": {},
41 | "outputs": [
42 | {
43 | "ename": "KeyError",
44 | "evalue": "('a', 'b')",
45 | "output_type": "error",
46 | "traceback": [
47 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
48 | "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
49 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m#2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m\"a\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"b\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"c\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'a'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'b'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
50 | "\u001b[0;31mKeyError\u001b[0m: ('a', 'b')"
51 | ]
52 | }
53 | ],
54 | "source": [
55 | "#2\n",
56 | "a={\"a\":1,\"b\":2,\"c\":3}\n",
57 | "print(a['a','b'])"
58 | ]
59 | },
60 | {
61 | "cell_type": "code",
62 | "execution_count": 4,
63 | "metadata": {},
64 | "outputs": [
65 | {
66 | "name": "stdout",
67 | "output_type": "stream",
68 | "text": [
69 | "3\n"
70 | ]
71 | }
72 | ],
73 | "source": [
74 | "#3\n",
75 | "fruit = {}\n",
76 | "\n",
77 | "def addone(index):\n",
78 | " if index in fruit:\n",
79 | " fruit[index] += 1\n",
80 | " else:\n",
81 | " fruit[index] = 1\n",
82 | " \n",
83 | "addone('Apple')\n",
84 | "addone('Banana')\n",
85 | "addone('apple')\n",
86 | "print (len(fruit))"
87 | ]
88 | },
89 | {
90 | "cell_type": "markdown",
91 | "metadata": {},
92 | "source": [
93 | "
"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": 5,
99 | "metadata": {},
100 | "outputs": [
101 | {
102 | "name": "stdout",
103 | "output_type": "stream",
104 | "text": [
105 | "4\n"
106 | ]
107 | }
108 | ],
109 | "source": [
110 | "#4\n",
111 | "arr = {}\n",
112 | "arr[1] = 1\n",
113 | "arr['1'] = 2\n",
114 | "arr[1] += 1\n",
115 | "\n",
116 | "sum = 0\n",
117 | "for k in arr:\n",
118 | " sum += arr[k]\n",
119 | "\n",
120 | "print (sum)"
121 | ]
122 | },
123 | {
124 | "cell_type": "code",
125 | "execution_count": 8,
126 | "metadata": {},
127 | "outputs": [
128 | {
129 | "name": "stdout",
130 | "output_type": "stream",
131 | "text": [
132 | "6\n"
133 | ]
134 | }
135 | ],
136 | "source": [
137 | "#5\n",
138 | "my_dict = {}\n",
139 | "my_dict[1] = 1\n",
140 | "my_dict['1'] = 2\n",
141 | "my_dict[1.0] = 4\n",
142 | "\n",
143 | "sum = 0\n",
144 | "for k in my_dict:\n",
145 | " sum += my_dict[k]\n",
146 | " \n",
147 | "print (sum)"
148 | ]
149 | },
150 | {
151 | "cell_type": "markdown",
152 | "metadata": {},
153 | "source": [
154 | "
"
155 | ]
156 | },
157 | {
158 | "cell_type": "code",
159 | "execution_count": 9,
160 | "metadata": {},
161 | "outputs": [
162 | {
163 | "name": "stdout",
164 | "output_type": "stream",
165 | "text": [
166 | "30\n",
167 | "{(1, 2, 4): 8, (4, 2, 1): 10, (1, 2): 12}\n"
168 | ]
169 | }
170 | ],
171 | "source": [
172 | "#6\n",
173 | "my_dict = {}\n",
174 | "my_dict[(1,2,4)] = 8\n",
175 | "my_dict[(4,2,1)] = 10\n",
176 | "my_dict[(1,2)] = 12\n",
177 | "\n",
178 | "sum = 0\n",
179 | "for k in my_dict:\n",
180 | " sum += my_dict[k]\n",
181 | "\n",
182 | "print (sum)\n",
183 | "print(my_dict)"
184 | ]
185 | },
186 | {
187 | "cell_type": "code",
188 | "execution_count": 10,
189 | "metadata": {},
190 | "outputs": [
191 | {
192 | "ename": "TypeError",
193 | "evalue": "unhashable type: 'dict'",
194 | "output_type": "error",
195 | "traceback": [
196 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
197 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
198 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mcrates\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'box'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbox\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mcrates\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'jars'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjars\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 10\u001b[0;31m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcrates\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mbox\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
199 | "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'dict'"
200 | ]
201 | }
202 | ],
203 | "source": [
204 | "#7\n",
205 | "box = {}\n",
206 | "jars = {}\n",
207 | "crates = {}\n",
208 | "box['biscuit'] = 1\n",
209 | "box['cake'] = 3\n",
210 | "jars['jam'] = 4\n",
211 | "crates['box'] = box\n",
212 | "crates['jars'] = jars\n",
213 | "print (len(crates[box]))"
214 | ]
215 | },
216 | {
217 | "cell_type": "markdown",
218 | "metadata": {},
219 | "source": [
220 | "
"
221 | ]
222 | },
223 | {
224 | "cell_type": "code",
225 | "execution_count": 11,
226 | "metadata": {},
227 | "outputs": [
228 | {
229 | "name": "stdout",
230 | "output_type": "stream",
231 | "text": [
232 | "96\n",
233 | "98\n",
234 | "97\n"
235 | ]
236 | }
237 | ],
238 | "source": [
239 | "#8\n",
240 | "dict = {'c': 97, 'a': 96, 'b': 98}\n",
241 | "\n",
242 | "for _ in sorted(dict):\n",
243 | " print (dict[_])"
244 | ]
245 | },
246 | {
247 | "cell_type": "code",
248 | "execution_count": 12,
249 | "metadata": {},
250 | "outputs": [
251 | {
252 | "name": "stdout",
253 | "output_type": "stream",
254 | "text": [
255 | "False\n"
256 | ]
257 | }
258 | ],
259 | "source": [
260 | "#9\n",
261 | "rec = {\"Name\" : \"Python\", \"Age\":\"20\"}\n",
262 | "r = rec.copy()\n",
263 | "print(id(r) == id(rec))"
264 | ]
265 | },
266 | {
267 | "cell_type": "code",
268 | "execution_count": 13,
269 | "metadata": {},
270 | "outputs": [
271 | {
272 | "name": "stdout",
273 | "output_type": "stream",
274 | "text": [
275 | "False\n"
276 | ]
277 | }
278 | ],
279 | "source": [
280 | "#10\n",
281 | "rec = {\"Name\" : \"Python\", \"Age\":\"20\", \"Addr\" : \"NJ\", \"Country\" : \"USA\"}\n",
282 | "id1 = id(rec)\n",
283 | "del rec\n",
284 | "rec = {\"Name\" : \"Python\", \"Age\":\"20\", \"Addr\" : \"NJ\", \"Country\" : \"USA\"}\n",
285 | "id2 = id(rec)\n",
286 | "print(id1 == id2)"
287 | ]
288 | },
289 | {
290 | "cell_type": "code",
291 | "execution_count": null,
292 | "metadata": {
293 | "collapsed": true
294 | },
295 | "outputs": [],
296 | "source": []
297 | }
298 | ],
299 | "metadata": {
300 | "kernelspec": {
301 | "display_name": "Python 3",
302 | "language": "python",
303 | "name": "python3"
304 | },
305 | "language_info": {
306 | "codemirror_mode": {
307 | "name": "ipython",
308 | "version": 3
309 | },
310 | "file_extension": ".py",
311 | "mimetype": "text/x-python",
312 | "name": "python",
313 | "nbconvert_exporter": "python",
314 | "pygments_lexer": "ipython3",
315 | "version": "3.6.8"
316 | }
317 | },
318 | "nbformat": 4,
319 | "nbformat_minor": 2
320 | }
321 |
--------------------------------------------------------------------------------
/output_based_questions/Day15.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Output Based Questions
\n",
8 | "\n",
9 | "
"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {
16 | "collapsed": true
17 | },
18 | "outputs": [],
19 | "source": [
20 | "# Answer-> A\n",
21 | "temp=np.genfromtxt(filename,filling_values=filling_values)"
22 | ]
23 | },
24 | {
25 | "cell_type": "markdown",
26 | "metadata": {},
27 | "source": [
28 | "
"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": null,
34 | "metadata": {
35 | "collapsed": true
36 | },
37 | "outputs": [],
38 | "source": [
39 | "#Answer-> A \n",
40 | "link = https://docs.google.com/spreadsheets/d/...source = StringIO.StringIO(requests.get(link).content))\n",
41 | "data = pd.read_csv(source)"
42 | ]
43 | },
44 | {
45 | "cell_type": "markdown",
46 | "metadata": {},
47 | "source": [
48 | "
"
49 | ]
50 | },
51 | {
52 | "cell_type": "code",
53 | "execution_count": 2,
54 | "metadata": {},
55 | "outputs": [
56 | {
57 | "name": "stderr",
58 | "output_type": "stream",
59 | "text": [
60 | "/home/shashank/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
61 | " return f(*args, **kwds)\n",
62 | "/home/shashank/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
63 | " return f(*args, **kwds)\n",
64 | "/home/shashank/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
65 | " return f(*args, **kwds)\n"
66 | ]
67 | }
68 | ],
69 | "source": [
70 | "import pandas as pd\n",
71 | "import numpy as np\n",
72 | "train = pd.DataFrame({'id':[1,2,4],'features':[[\"A\",\"B\",\"C\"],[\"A\",\"D\",\"E\"],[\"C\",\"D\",\"F\"]]})\n",
73 | "train['features_t'] = train[\"features\"].apply(lambda x: \" \".join([\"_\".join(i.split(\" \")) for i in x]))"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": 3,
79 | "metadata": {},
80 | "outputs": [
81 | {
82 | "name": "stdout",
83 | "output_type": "stream",
84 | "text": [
85 | "0 A B C\n",
86 | "1 A D E\n",
87 | "2 C D F\n",
88 | "Name: features_t, dtype: object\n"
89 | ]
90 | }
91 | ],
92 | "source": [
93 | "print(train[\"features_t\"])"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": 4,
99 | "metadata": {
100 | "collapsed": true
101 | },
102 | "outputs": [],
103 | "source": [
104 | "#Answer A"
105 | ]
106 | },
107 | {
108 | "cell_type": "markdown",
109 | "metadata": {},
110 | "source": [
111 | "
"
112 | ]
113 | },
114 | {
115 | "cell_type": "code",
116 | "execution_count": 5,
117 | "metadata": {
118 | "collapsed": true
119 | },
120 | "outputs": [],
121 | "source": [
122 | "#Answer :- A"
123 | ]
124 | },
125 | {
126 | "cell_type": "markdown",
127 | "metadata": {},
128 | "source": [
129 | "
"
130 | ]
131 | },
132 | {
133 | "cell_type": "code",
134 | "execution_count": 10,
135 | "metadata": {},
136 | "outputs": [],
137 | "source": [
138 | "df = pd.DataFrame(list(zip(['ff', 'gg', 'hh', 'yy'],[24, 12, 48, 30])),columns = ['Name', 'Age'])"
139 | ]
140 | },
141 | {
142 | "cell_type": "code",
143 | "execution_count": 20,
144 | "metadata": {},
145 | "outputs": [
146 | {
147 | "data": {
148 | "text/plain": [
149 | "0 ff\n",
150 | "1 gg\n",
151 | "2 hh\n",
152 | "3 yy\n",
153 | "Name: Name, dtype: object"
154 | ]
155 | },
156 | "execution_count": 20,
157 | "metadata": {},
158 | "output_type": "execute_result"
159 | }
160 | ],
161 | "source": [
162 | "df['Name']"
163 | ]
164 | },
165 | {
166 | "cell_type": "code",
167 | "execution_count": 19,
168 | "metadata": {},
169 | "outputs": [
170 | {
171 | "data": {
172 | "text/plain": [
173 | "0 ff\n",
174 | "1 gg\n",
175 | "2 hh\n",
176 | "3 yy\n",
177 | "Name: Name, dtype: object"
178 | ]
179 | },
180 | "execution_count": 19,
181 | "metadata": {},
182 | "output_type": "execute_result"
183 | }
184 | ],
185 | "source": [
186 | "df.loc[:,\"Name\"]"
187 | ]
188 | },
189 | {
190 | "cell_type": "code",
191 | "execution_count": 21,
192 | "metadata": {
193 | "collapsed": true
194 | },
195 | "outputs": [],
196 | "source": [
197 | "# Answer B"
198 | ]
199 | },
200 | {
201 | "cell_type": "markdown",
202 | "metadata": {},
203 | "source": [
204 | "
"
205 | ]
206 | },
207 | {
208 | "cell_type": "code",
209 | "execution_count": 25,
210 | "metadata": {},
211 | "outputs": [],
212 | "source": [
213 | "#Answer C\n",
214 | "from sklearn.tree import DecisionTreeClassifier"
215 | ]
216 | },
217 | {
218 | "cell_type": "code",
219 | "execution_count": null,
220 | "metadata": {
221 | "collapsed": true
222 | },
223 | "outputs": [],
224 | "source": []
225 | },
226 | {
227 | "cell_type": "code",
228 | "execution_count": null,
229 | "metadata": {
230 | "collapsed": true
231 | },
232 | "outputs": [],
233 | "source": []
234 | }
235 | ],
236 | "metadata": {
237 | "kernelspec": {
238 | "display_name": "Python 3",
239 | "language": "python",
240 | "name": "python3"
241 | },
242 | "language_info": {
243 | "codemirror_mode": {
244 | "name": "ipython",
245 | "version": 3
246 | },
247 | "file_extension": ".py",
248 | "mimetype": "text/x-python",
249 | "name": "python",
250 | "nbconvert_exporter": "python",
251 | "pygments_lexer": "ipython3",
252 | "version": "3.6.8"
253 | }
254 | },
255 | "nbformat": 4,
256 | "nbformat_minor": 2
257 | }
258 |
--------------------------------------------------------------------------------
/output_based_questions/day10.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# OUTPUT RELATED QUESTIONS\n",
8 | "\n",
9 | "## DAY10"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {},
15 | "source": [
16 | "
"
17 | ]
18 | },
19 | {
20 | "cell_type": "code",
21 | "execution_count": 2,
22 | "metadata": {},
23 | "outputs": [
24 | {
25 | "name": "stdout",
26 | "output_type": "stream",
27 | "text": [
28 | "0\n"
29 | ]
30 | }
31 | ],
32 | "source": [
33 | "#1\n",
34 | "init_tuple = ()\n",
35 | "print (init_tuple.__len__())"
36 | ]
37 | },
38 | {
39 | "cell_type": "code",
40 | "execution_count": 3,
41 | "metadata": {},
42 | "outputs": [
43 | {
44 | "name": "stdout",
45 | "output_type": "stream",
46 | "text": [
47 | "True\n"
48 | ]
49 | }
50 | ],
51 | "source": [
52 | "#2\n",
53 | "init_tuple_a = 'a', 'b'\n",
54 | "init_tuple_b = ('a', 'b')\n",
55 | "\n",
56 | "print (init_tuple_a == init_tuple_b)"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": 4,
62 | "metadata": {},
63 | "outputs": [
64 | {
65 | "name": "stdout",
66 | "output_type": "stream",
67 | "text": [
68 | "('1', '2', '3', '4')\n"
69 | ]
70 | }
71 | ],
72 | "source": [
73 | "#3\n",
74 | "init_tuple_a = '1', '2'\n",
75 | "init_tuple_b = ('3', '4')\n",
76 | "\n",
77 | "print (init_tuple_a + init_tuple_b)"
78 | ]
79 | },
80 | {
81 | "cell_type": "markdown",
82 | "metadata": {},
83 | "source": [
84 | "
"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": 6,
90 | "metadata": {},
91 | "outputs": [
92 | {
93 | "name": "stdout",
94 | "output_type": "stream",
95 | "text": [
96 | "10\n"
97 | ]
98 | },
99 | {
100 | "data": {
101 | "text/plain": [
102 | "[None]"
103 | ]
104 | },
105 | "execution_count": 6,
106 | "metadata": {},
107 | "output_type": "execute_result"
108 | }
109 | ],
110 | "source": [
111 | "#4\n",
112 | "init_tuple_a = 1, 2\n",
113 | "init_tuple_b = (3, 4)\n",
114 | "\n",
115 | "[print(sum(x)) for x in [init_tuple_a + init_tuple_b]]"
116 | ]
117 | },
118 | {
119 | "cell_type": "code",
120 | "execution_count": 7,
121 | "metadata": {},
122 | "outputs": [
123 | {
124 | "name": "stdout",
125 | "output_type": "stream",
126 | "text": [
127 | "6\n"
128 | ]
129 | }
130 | ],
131 | "source": [
132 | "#5\n",
133 | "init_tuple = [(0, 1), (1, 2), (2, 3)]\n",
134 | "\n",
135 | "result = sum(n for _, n in init_tuple)\n",
136 | "\n",
137 | "print(result)"
138 | ]
139 | },
140 | {
141 | "cell_type": "code",
142 | "execution_count": 8,
143 | "metadata": {
144 | "collapsed": true
145 | },
146 | "outputs": [],
147 | "source": [
148 | "#6 A & C are the answers"
149 | ]
150 | },
151 | {
152 | "cell_type": "markdown",
153 | "metadata": {},
154 | "source": [
155 | "
"
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": 11,
161 | "metadata": {},
162 | "outputs": [
163 | {
164 | "name": "stdout",
165 | "output_type": "stream",
166 | "text": [
167 | "()\n"
168 | ]
169 | }
170 | ],
171 | "source": [
172 | "#7\n",
173 | "l = [1, 2, 3]\n",
174 | "\n",
175 | "init_tuple = ('Python',) * (l.__len__() - l[::-1][0])\n",
176 | "\n",
177 | "print(init_tuple)"
178 | ]
179 | },
180 | {
181 | "cell_type": "code",
182 | "execution_count": 14,
183 | "metadata": {},
184 | "outputs": [
185 | {
186 | "name": "stdout",
187 | "output_type": "stream",
188 | "text": [
189 | "\n"
190 | ]
191 | }
192 | ],
193 | "source": [
194 | "#8\n",
195 | "init_tuple = ('Python') * 3\n",
196 | "\n",
197 | "print(type(init_tuple))"
198 | ]
199 | },
200 | {
201 | "cell_type": "code",
202 | "execution_count": 15,
203 | "metadata": {},
204 | "outputs": [
205 | {
206 | "ename": "TypeError",
207 | "evalue": "'tuple' object does not support item assignment",
208 | "output_type": "error",
209 | "traceback": [
210 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
211 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
212 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0minit_tuple\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0minit_tuple\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minit_tuple\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
213 | "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
214 | ]
215 | }
216 | ],
217 | "source": [
218 | "#9\n",
219 | "init_tuple = (1,) * 3\n",
220 | "\n",
221 | "init_tuple[0] = 2\n",
222 | "\n",
223 | "print(init_tuple)"
224 | ]
225 | },
226 | {
227 | "cell_type": "markdown",
228 | "metadata": {},
229 | "source": [
230 | "
"
231 | ]
232 | },
233 | {
234 | "cell_type": "code",
235 | "execution_count": 16,
236 | "metadata": {},
237 | "outputs": [
238 | {
239 | "name": "stdout",
240 | "output_type": "stream",
241 | "text": [
242 | "4\n"
243 | ]
244 | }
245 | ],
246 | "source": [
247 | "#10\n",
248 | "init_tuple = ((1, 2),) * 7\n",
249 | "\n",
250 | "print(len(init_tuple[3:8]))"
251 | ]
252 | },
253 | {
254 | "cell_type": "code",
255 | "execution_count": null,
256 | "metadata": {
257 | "collapsed": true
258 | },
259 | "outputs": [],
260 | "source": []
261 | }
262 | ],
263 | "metadata": {
264 | "kernelspec": {
265 | "display_name": "Python 3",
266 | "language": "python",
267 | "name": "python3"
268 | },
269 | "language_info": {
270 | "codemirror_mode": {
271 | "name": "ipython",
272 | "version": 3
273 | },
274 | "file_extension": ".py",
275 | "mimetype": "text/x-python",
276 | "name": "python",
277 | "nbconvert_exporter": "python",
278 | "pygments_lexer": "ipython3",
279 | "version": "3.6.8"
280 | }
281 | },
282 | "nbformat": 4,
283 | "nbformat_minor": 2
284 | }
285 |
--------------------------------------------------------------------------------
/output_based_questions/day12.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Questions related to Python
\n",
8 | "\n"
9 | ]
10 | },
11 | {
12 | "cell_type": "markdown",
13 | "metadata": {},
14 | "source": [
15 | "
"
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {},
21 | "source": [
22 | "## What is Python?\n",
23 | "\n",
24 | "Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed. "
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "metadata": {},
30 | "source": [
31 | "## Features of Python.\n",
32 | "\n",
33 | "1. Easy to Learn and use\n",
34 | "2. Expressive Language\n",
35 | "3. Interpreted Language\n",
36 | "4. Cross Platform \n",
37 | "5. Free and Open Source"
38 | ]
39 | },
40 | {
41 | "cell_type": "markdown",
42 | "metadata": {},
43 | "source": [
44 | "## Python Path Environment Variable\n",
45 | "\n",
46 | " PYTHONPATH is used to assist in import module lookup. So when you import modules, PYTHONPATH is also looked into to check which directories might contain the imported module."
47 | ]
48 | },
49 | {
50 | "cell_type": "markdown",
51 | "metadata": {},
52 | "source": [
53 | "## PYTHONSTARTUP\n",
54 | "\n",
55 | "PYTHONSTARTUP is an environment variable you will define specifying the location of the path to a python file. This python script will be run by python before starting the python interactive mode (interpreter). You can use it for various enhancements like preloading modules, setting colors."
56 | ]
57 | },
58 | {
59 | "cell_type": "markdown",
60 | "metadata": {},
61 | "source": [
62 | "## PYTHONCASEOK\n",
63 | "\n",
64 | "It is used in Windows to instruct Python to find the first case-insensitive match in an import statement. Set this variable with any value to activate it.\n",
65 | "\n",
66 | "## PYTHONHOME\n",
67 | "\n",
68 | "It is an alternative module search path. It is usually embedded in PYTHONSTARTUP or PYTHONPATH directories to make switching of module libraries easy."
69 | ]
70 | },
71 | {
72 | "cell_type": "markdown",
73 | "metadata": {},
74 | "source": [
75 | "## Supported DataTypes\n",
76 | "\n",
77 | "There are eight kinds of types supported by PyTables:\n",
78 | "\n",
79 | " bool: Boolean (true/false) types. Supported precisions: 8 (default) bits.\n",
80 | "\n",
81 | " int: Signed integer types. Supported precisions: 8, 16, 32 (default) and 64 bits.\n",
82 | "\n",
83 | " uint: Unsigned integer types. Supported precisions: 8, 16, 32 (default) and 64 bits.\n",
84 | "\n",
85 | " float: Floating point types. Supported precisions: 16, 32, 64 (default) bits and extended precision floating point (see note on floating point types).\n",
86 | "\n",
87 | " complex: Complex number types. Supported precisions: 64 (32+32), 128 (64+64, default) bits and extended precision complex (see note on floating point types).\n",
88 | "\n",
89 | " string: Raw string types. Supported precisions: 8-bit positive multiples.\n",
90 | "\n",
91 | " time: Data/time types. Supported precisions: 32 and 64 (default) bits.\n",
92 | "\n",
93 | " enum: Enumerated types. Precision depends on base type.\n"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": 1,
99 | "metadata": {},
100 | "outputs": [
101 | {
102 | "name": "stdout",
103 | "output_type": "stream",
104 | "text": [
105 | "HELLO WOrld\n"
106 | ]
107 | }
108 | ],
109 | "source": [
110 | "a=\"HELLO WOrld\"\n",
111 | "print(a)"
112 | ]
113 | },
114 | {
115 | "cell_type": "code",
116 | "execution_count": 2,
117 | "metadata": {},
118 | "outputs": [
119 | {
120 | "name": "stdout",
121 | "output_type": "stream",
122 | "text": [
123 | "H\n"
124 | ]
125 | }
126 | ],
127 | "source": [
128 | "print(a[0])"
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": 3,
134 | "metadata": {},
135 | "outputs": [
136 | {
137 | "name": "stdout",
138 | "output_type": "stream",
139 | "text": [
140 | "LLO\n"
141 | ]
142 | }
143 | ],
144 | "source": [
145 | "print(a[2:5])"
146 | ]
147 | },
148 | {
149 | "cell_type": "code",
150 | "execution_count": 4,
151 | "metadata": {},
152 | "outputs": [
153 | {
154 | "name": "stdout",
155 | "output_type": "stream",
156 | "text": [
157 | "LLO WOrld\n"
158 | ]
159 | }
160 | ],
161 | "source": [
162 | "print(a[2:])"
163 | ]
164 | },
165 | {
166 | "cell_type": "code",
167 | "execution_count": 5,
168 | "metadata": {},
169 | "outputs": [
170 | {
171 | "name": "stdout",
172 | "output_type": "stream",
173 | "text": [
174 | "HELLO WOrldTEST\n"
175 | ]
176 | }
177 | ],
178 | "source": [
179 | "print(a+\"TEST\")"
180 | ]
181 | },
182 | {
183 | "cell_type": "code",
184 | "execution_count": 6,
185 | "metadata": {},
186 | "outputs": [
187 | {
188 | "name": "stdout",
189 | "output_type": "stream",
190 | "text": [
191 | "['abcd', 786, 2.23, 'john', 70.2]\n"
192 | ]
193 | }
194 | ],
195 | "source": [
196 | "lst=['abcd',786,2.23,'john',70.2]\n",
197 | "print(lst)"
198 | ]
199 | },
200 | {
201 | "cell_type": "markdown",
202 | "metadata": {},
203 | "source": [
204 | "
"
205 | ]
206 | },
207 | {
208 | "cell_type": "code",
209 | "execution_count": 7,
210 | "metadata": {},
211 | "outputs": [
212 | {
213 | "name": "stdout",
214 | "output_type": "stream",
215 | "text": [
216 | "abcd\n"
217 | ]
218 | }
219 | ],
220 | "source": [
221 | "print(lst[0])"
222 | ]
223 | },
224 | {
225 | "cell_type": "code",
226 | "execution_count": 8,
227 | "metadata": {},
228 | "outputs": [
229 | {
230 | "name": "stdout",
231 | "output_type": "stream",
232 | "text": [
233 | "[786, 2.23]\n"
234 | ]
235 | }
236 | ],
237 | "source": [
238 | "print(lst[1:3])"
239 | ]
240 | },
241 | {
242 | "cell_type": "code",
243 | "execution_count": 9,
244 | "metadata": {},
245 | "outputs": [
246 | {
247 | "name": "stdout",
248 | "output_type": "stream",
249 | "text": [
250 | "[2.23, 'john', 70.2]\n"
251 | ]
252 | }
253 | ],
254 | "source": [
255 | "print(lst[2:])"
256 | ]
257 | },
258 | {
259 | "cell_type": "code",
260 | "execution_count": 10,
261 | "metadata": {},
262 | "outputs": [
263 | {
264 | "name": "stdout",
265 | "output_type": "stream",
266 | "text": [
267 | "[123, 'john', 123, 'john']\n"
268 | ]
269 | }
270 | ],
271 | "source": [
272 | "tinylist=[123,'john']\n",
273 | "print(tinylist*2)"
274 | ]
275 | },
276 | {
277 | "cell_type": "code",
278 | "execution_count": 11,
279 | "metadata": {},
280 | "outputs": [
281 | {
282 | "name": "stdout",
283 | "output_type": "stream",
284 | "text": [
285 | "['abcd', 786, 2.23, 'john', 70.2, 123, 'john']\n"
286 | ]
287 | }
288 | ],
289 | "source": [
290 | "print(lst+tinylist)"
291 | ]
292 | },
293 | {
294 | "cell_type": "markdown",
295 | "metadata": {},
296 | "source": [
297 | "## Tuples\n",
298 | "\n",
299 | "A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. Creating a tuple is as simple as putting different comma-separated values."
300 | ]
301 | },
302 | {
303 | "cell_type": "markdown",
304 | "metadata": {},
305 | "source": [
306 | "## Difference between tuples and lists\n",
307 | "\n",
308 | "The main difference between lists and a tuples is the fact that lists are mutable whereas tuples are immutable. A mutable data type means that a python object of this type can be modified. Let's create a list and assign it to a variable."
309 | ]
310 | },
311 | {
312 | "cell_type": "code",
313 | "execution_count": 12,
314 | "metadata": {},
315 | "outputs": [
316 | {
317 | "name": "stdout",
318 | "output_type": "stream",
319 | "text": [
320 | "('abcd', 786, 2.23, 'john', 70.2)\n"
321 | ]
322 | }
323 | ],
324 | "source": [
325 | "tup=('abcd',786,2.23,'john',70.2)\n",
326 | "print(tup)"
327 | ]
328 | },
329 | {
330 | "cell_type": "code",
331 | "execution_count": 13,
332 | "metadata": {},
333 | "outputs": [
334 | {
335 | "name": "stdout",
336 | "output_type": "stream",
337 | "text": [
338 | "abcd\n"
339 | ]
340 | }
341 | ],
342 | "source": [
343 | "print(tup[0])"
344 | ]
345 | },
346 | {
347 | "cell_type": "code",
348 | "execution_count": 14,
349 | "metadata": {},
350 | "outputs": [
351 | {
352 | "name": "stdout",
353 | "output_type": "stream",
354 | "text": [
355 | "(786, 2.23)\n"
356 | ]
357 | }
358 | ],
359 | "source": [
360 | "print(tup[1:3])"
361 | ]
362 | },
363 | {
364 | "cell_type": "code",
365 | "execution_count": 15,
366 | "metadata": {},
367 | "outputs": [
368 | {
369 | "name": "stdout",
370 | "output_type": "stream",
371 | "text": [
372 | "(2.23, 'john', 70.2)\n"
373 | ]
374 | }
375 | ],
376 | "source": [
377 | "print(tup[2:])"
378 | ]
379 | },
380 | {
381 | "cell_type": "code",
382 | "execution_count": 16,
383 | "metadata": {},
384 | "outputs": [
385 | {
386 | "name": "stdout",
387 | "output_type": "stream",
388 | "text": [
389 | "(123, 'john', 123, 'john')\n"
390 | ]
391 | }
392 | ],
393 | "source": [
394 | "tiny=(123,'john')\n",
395 | "print(tiny*2)"
396 | ]
397 | },
398 | {
399 | "cell_type": "code",
400 | "execution_count": 17,
401 | "metadata": {},
402 | "outputs": [
403 | {
404 | "name": "stdout",
405 | "output_type": "stream",
406 | "text": [
407 | "('abcd', 786, 2.23, 'john', 70.2, 123, 'john')\n"
408 | ]
409 | }
410 | ],
411 | "source": [
412 | "print(tup+tiny)"
413 | ]
414 | },
415 | {
416 | "cell_type": "markdown",
417 | "metadata": {},
418 | "source": [
419 | "## Python Dictionaries\n",
420 | "\n",
421 | "A dictionary maps a set of objects (keys) to another set of objects (values). A Python dictionary is a mapping of unique keys to values. Dictionaries are mutable, which means they can be changed. The values that the keys point to can be any Python value."
422 | ]
423 | },
424 | {
425 | "cell_type": "markdown",
426 | "metadata": {},
427 | "source": [
428 | "
"
429 | ]
430 | },
431 | {
432 | "cell_type": "code",
433 | "execution_count": 18,
434 | "metadata": {
435 | "collapsed": true
436 | },
437 | "outputs": [],
438 | "source": [
439 | "#1\n",
440 | "dict1={\"name\":\"Shashank\",\"age\":\"21\"}"
441 | ]
442 | },
443 | {
444 | "cell_type": "code",
445 | "execution_count": 24,
446 | "metadata": {},
447 | "outputs": [
448 | {
449 | "data": {
450 | "text/plain": [
451 | "['name', 'age']"
452 | ]
453 | },
454 | "execution_count": 24,
455 | "metadata": {},
456 | "output_type": "execute_result"
457 | }
458 | ],
459 | "source": [
460 | "#2\n",
461 | "list(dict1.keys())"
462 | ]
463 | },
464 | {
465 | "cell_type": "code",
466 | "execution_count": 25,
467 | "metadata": {},
468 | "outputs": [
469 | {
470 | "data": {
471 | "text/plain": [
472 | "['Shashank', '21']"
473 | ]
474 | },
475 | "execution_count": 25,
476 | "metadata": {},
477 | "output_type": "execute_result"
478 | }
479 | ],
480 | "source": [
481 | "#3\n",
482 | "list(dict1.values())"
483 | ]
484 | },
485 | {
486 | "cell_type": "code",
487 | "execution_count": 26,
488 | "metadata": {
489 | "collapsed": true
490 | },
491 | "outputs": [],
492 | "source": [
493 | "#4\n",
494 | "a=\"1\"\n",
495 | "b=int(a)\n"
496 | ]
497 | },
498 | {
499 | "cell_type": "code",
500 | "execution_count": 28,
501 | "metadata": {},
502 | "outputs": [
503 | {
504 | "data": {
505 | "text/plain": [
506 | "'1'"
507 | ]
508 | },
509 | "execution_count": 28,
510 | "metadata": {},
511 | "output_type": "execute_result"
512 | }
513 | ],
514 | "source": [
515 | "a"
516 | ]
517 | },
518 | {
519 | "cell_type": "code",
520 | "execution_count": 29,
521 | "metadata": {},
522 | "outputs": [
523 | {
524 | "data": {
525 | "text/plain": [
526 | "1"
527 | ]
528 | },
529 | "execution_count": 29,
530 | "metadata": {},
531 | "output_type": "execute_result"
532 | }
533 | ],
534 | "source": [
535 | "b"
536 | ]
537 | },
538 | {
539 | "cell_type": "code",
540 | "execution_count": 32,
541 | "metadata": {},
542 | "outputs": [],
543 | "source": [
544 | "#5\n",
545 | "a=\"3520.25\"\n",
546 | "b=float(a)"
547 | ]
548 | },
549 | {
550 | "cell_type": "code",
551 | "execution_count": 33,
552 | "metadata": {},
553 | "outputs": [
554 | {
555 | "data": {
556 | "text/plain": [
557 | "3520.25"
558 | ]
559 | },
560 | "execution_count": 33,
561 | "metadata": {},
562 | "output_type": "execute_result"
563 | }
564 | ],
565 | "source": [
566 | "b"
567 | ]
568 | },
569 | {
570 | "cell_type": "code",
571 | "execution_count": 34,
572 | "metadata": {
573 | "collapsed": true
574 | },
575 | "outputs": [],
576 | "source": [
577 | "#6\n",
578 | "a=[\"ab\",12,\"32\"]\n",
579 | "b=str(a)"
580 | ]
581 | },
582 | {
583 | "cell_type": "code",
584 | "execution_count": 35,
585 | "metadata": {},
586 | "outputs": [
587 | {
588 | "data": {
589 | "text/plain": [
590 | "\"['ab', 12, '32']\""
591 | ]
592 | },
593 | "execution_count": 35,
594 | "metadata": {},
595 | "output_type": "execute_result"
596 | }
597 | ],
598 | "source": [
599 | "b"
600 | ]
601 | },
602 | {
603 | "cell_type": "code",
604 | "execution_count": 37,
605 | "metadata": {},
606 | "outputs": [
607 | {
608 | "data": {
609 | "text/plain": [
610 | "b'\\x80\\x03X\\x05\\x00\\x00\\x00helloq\\x00.'"
611 | ]
612 | },
613 | "execution_count": 37,
614 | "metadata": {},
615 | "output_type": "execute_result"
616 | }
617 | ],
618 | "source": [
619 | "#7\n",
620 | "import pickle\n",
621 | "pickle.dumps(\"hello\")"
622 | ]
623 | },
624 | {
625 | "cell_type": "code",
626 | "execution_count": 38,
627 | "metadata": {},
628 | "outputs": [
629 | {
630 | "data": {
631 | "text/plain": [
632 | "('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd')"
633 | ]
634 | },
635 | "execution_count": 38,
636 | "metadata": {},
637 | "output_type": "execute_result"
638 | }
639 | ],
640 | "source": [
641 | "#8\n",
642 | "a=\"hello world\"\n",
643 | "tuple(a)"
644 | ]
645 | },
646 | {
647 | "cell_type": "code",
648 | "execution_count": 39,
649 | "metadata": {},
650 | "outputs": [
651 | {
652 | "data": {
653 | "text/plain": [
654 | "['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']"
655 | ]
656 | },
657 | "execution_count": 39,
658 | "metadata": {},
659 | "output_type": "execute_result"
660 | }
661 | ],
662 | "source": [
663 | "#9\n",
664 | "list(a)"
665 | ]
666 | },
667 | {
668 | "cell_type": "code",
669 | "execution_count": 40,
670 | "metadata": {},
671 | "outputs": [
672 | {
673 | "data": {
674 | "text/plain": [
675 | "{' ', 'd', 'e', 'h', 'l', 'o', 'r', 'w'}"
676 | ]
677 | },
678 | "execution_count": 40,
679 | "metadata": {},
680 | "output_type": "execute_result"
681 | }
682 | ],
683 | "source": [
684 | "#10\n",
685 | "set(a)"
686 | ]
687 | },
688 | {
689 | "cell_type": "code",
690 | "execution_count": 41,
691 | "metadata": {},
692 | "outputs": [
693 | {
694 | "data": {
695 | "text/plain": [
696 | "{1: 2, 3: 4}"
697 | ]
698 | },
699 | "execution_count": 41,
700 | "metadata": {},
701 | "output_type": "execute_result"
702 | }
703 | ],
704 | "source": [
705 | "#11\n",
706 | "a=[(1,2),(3,4)]\n",
707 | "dict(a)"
708 | ]
709 | },
710 | {
711 | "cell_type": "code",
712 | "execution_count": 42,
713 | "metadata": {},
714 | "outputs": [
715 | {
716 | "data": {
717 | "text/plain": [
718 | "frozenset({(1, 2), (3, 4)})"
719 | ]
720 | },
721 | "execution_count": 42,
722 | "metadata": {},
723 | "output_type": "execute_result"
724 | }
725 | ],
726 | "source": [
727 | "#12\n",
728 | "frozenset(a)"
729 | ]
730 | },
731 | {
732 | "cell_type": "code",
733 | "execution_count": 46,
734 | "metadata": {},
735 | "outputs": [
736 | {
737 | "data": {
738 | "text/plain": [
739 | "'\\x0c'"
740 | ]
741 | },
742 | "execution_count": 46,
743 | "metadata": {},
744 | "output_type": "execute_result"
745 | }
746 | ],
747 | "source": [
748 | "#13\n",
749 | "a=12\n",
750 | "chr(a)"
751 | ]
752 | },
753 | {
754 | "cell_type": "code",
755 | "execution_count": null,
756 | "metadata": {
757 | "collapsed": true
758 | },
759 | "outputs": [],
760 | "source": []
761 | }
762 | ],
763 | "metadata": {
764 | "kernelspec": {
765 | "display_name": "Python 3",
766 | "language": "python",
767 | "name": "python3"
768 | },
769 | "language_info": {
770 | "codemirror_mode": {
771 | "name": "ipython",
772 | "version": 3
773 | },
774 | "file_extension": ".py",
775 | "mimetype": "text/x-python",
776 | "name": "python",
777 | "nbconvert_exporter": "python",
778 | "pygments_lexer": "ipython3",
779 | "version": "3.6.8"
780 | }
781 | },
782 | "nbformat": 4,
783 | "nbformat_minor": 2
784 | }
785 |
--------------------------------------------------------------------------------
/output_based_questions/day13.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | " Output Based Questions
\n",
8 | "\n",
9 | "
"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": 1,
15 | "metadata": {},
16 | "outputs": [
17 | {
18 | "name": "stdout",
19 | "output_type": "stream",
20 | "text": [
21 | "10 {'c': 10}\n"
22 | ]
23 | }
24 | ],
25 | "source": [
26 | "def fun(a,**b):\n",
27 | " print(a,b)\n",
28 | "fun(10,c=10)"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": null,
34 | "metadata": {
35 | "collapsed": true
36 | },
37 | "outputs": [],
38 | "source": [
39 | "#4 Answer=C"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": 6,
45 | "metadata": {},
46 | "outputs": [
47 | {
48 | "name": "stdout",
49 | "output_type": "stream",
50 | "text": [
51 | "10 {'c': 10, 'd': 20, 'e': 30}\n"
52 | ]
53 | }
54 | ],
55 | "source": [
56 | "fun(10,c=10,d=20,e=30)"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": null,
62 | "metadata": {
63 | "collapsed": true
64 | },
65 | "outputs": [],
66 | "source": [
67 | "#5 Answer =C"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": 7,
73 | "metadata": {},
74 | "outputs": [
75 | {
76 | "name": "stdout",
77 | "output_type": "stream",
78 | "text": [
79 | "3\n",
80 | "1\n"
81 | ]
82 | }
83 | ],
84 | "source": [
85 | "def foo(fname,val):\n",
86 | " print(fname(val))\n",
87 | "foo(max,[1,2,3])\n",
88 | "foo(min,[1,2,3])\n",
89 | "#ans =A"
90 | ]
91 | },
92 | {
93 | "cell_type": "markdown",
94 | "metadata": {},
95 | "source": [
96 | "
"
97 | ]
98 | },
99 | {
100 | "cell_type": "code",
101 | "execution_count": 8,
102 | "metadata": {},
103 | "outputs": [
104 | {
105 | "ename": "UnboundLocalError",
106 | "evalue": "local variable 'total' referenced before assignment",
107 | "output_type": "error",
108 | "traceback": [
109 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
110 | "\u001b[0;31mUnboundLocalError\u001b[0m Traceback (most recent call last)",
111 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtotal\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mtotal\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfoo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
112 | "\u001b[0;32m\u001b[0m in \u001b[0;36mfoo\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mfoo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mtotal\u001b[0m\u001b[0;34m+=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtotal\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mtotal\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfoo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
113 | "\u001b[0;31mUnboundLocalError\u001b[0m: local variable 'total' referenced before assignment"
114 | ]
115 | }
116 | ],
117 | "source": [
118 | "def foo():\n",
119 | " total+=1\n",
120 | " return total\n",
121 | "total=0\n",
122 | "print(foo())\n",
123 | "\n",
124 | "# Answer =D"
125 | ]
126 | },
127 | {
128 | "cell_type": "code",
129 | "execution_count": 9,
130 | "metadata": {},
131 | "outputs": [
132 | {
133 | "name": "stdout",
134 | "output_type": "stream",
135 | "text": [
136 | "False\n"
137 | ]
138 | }
139 | ],
140 | "source": [
141 | "def foo(x):\n",
142 | " x=['def','abc']\n",
143 | " return id(x)\n",
144 | "q=['abc','def']\n",
145 | "print(id(q)==foo(q))"
146 | ]
147 | },
148 | {
149 | "cell_type": "code",
150 | "execution_count": null,
151 | "metadata": {
152 | "collapsed": true
153 | },
154 | "outputs": [],
155 | "source": [
156 | "#Ans=b"
157 | ]
158 | },
159 | {
160 | "cell_type": "markdown",
161 | "metadata": {},
162 | "source": [
163 | "
"
164 | ]
165 | },
166 | {
167 | "cell_type": "code",
168 | "execution_count": 10,
169 | "metadata": {},
170 | "outputs": [
171 | {
172 | "name": "stdout",
173 | "output_type": "stream",
174 | "text": [
175 | "[0]\n",
176 | "[0, 1]\n",
177 | "[0, 1, 2]\n"
178 | ]
179 | }
180 | ],
181 | "source": [
182 | "def foo(i,x=[]):\n",
183 | " x.append(i)\n",
184 | " return x\n",
185 | "for i in range(3):\n",
186 | " print(foo(i))"
187 | ]
188 | },
189 | {
190 | "cell_type": "code",
191 | "execution_count": null,
192 | "metadata": {
193 | "collapsed": true
194 | },
195 | "outputs": [],
196 | "source": []
197 | },
198 | {
199 | "cell_type": "code",
200 | "execution_count": null,
201 | "metadata": {
202 | "collapsed": true
203 | },
204 | "outputs": [],
205 | "source": []
206 | },
207 | {
208 | "cell_type": "code",
209 | "execution_count": null,
210 | "metadata": {
211 | "collapsed": true
212 | },
213 | "outputs": [],
214 | "source": []
215 | },
216 | {
217 | "cell_type": "code",
218 | "execution_count": null,
219 | "metadata": {
220 | "collapsed": true
221 | },
222 | "outputs": [],
223 | "source": []
224 | }
225 | ],
226 | "metadata": {
227 | "kernelspec": {
228 | "display_name": "Python 3",
229 | "language": "python",
230 | "name": "python3"
231 | },
232 | "language_info": {
233 | "codemirror_mode": {
234 | "name": "ipython",
235 | "version": 3
236 | },
237 | "file_extension": ".py",
238 | "mimetype": "text/x-python",
239 | "name": "python",
240 | "nbconvert_exporter": "python",
241 | "pygments_lexer": "ipython3",
242 | "version": "3.6.8"
243 | }
244 | },
245 | "nbformat": 4,
246 | "nbformat_minor": 2
247 | }
248 |
--------------------------------------------------------------------------------
/output_based_questions/day14.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Output Based Questions
\n",
8 | "\n",
9 | "
"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {},
15 | "source": [
16 | "
"
17 | ]
18 | },
19 | {
20 | "cell_type": "code",
21 | "execution_count": 1,
22 | "metadata": {
23 | "collapsed": true
24 | },
25 | "outputs": [],
26 | "source": [
27 | "txt = '''450\n",
28 | " 00:17:53,457 --> 00:17:56,175\n",
29 | " Okay, but, um,\n",
30 | " thanks for being with us.\n",
31 | "\n",
32 | "451\n",
33 | " 00:17:56,175 --> 00:17:58,616\n",
34 | " But, um, if there's any\n",
35 | " college kids watching,\n",
36 | "\n",
37 | "452\n",
38 | " 00:17:58,616 --> 00:18:01,610\n",
39 | " But, um, but, um, but, um,\n",
40 | " but, um, but, um,\n",
41 | "\n",
42 | "453\n",
43 | " 00:18:01,610 --> 00:18:03,656\n",
44 | " We have to drink, professor.\n",
45 | "\n",
46 | "454\n",
47 | " 00:18:03,656 --> 00:18:07,507\n",
48 | " It's the rules.\n",
49 | " She said \"But, um\"\n",
50 | "\n",
51 | "455\n",
52 | " 00:18:09,788 --> 00:18:12,515\n",
53 | " But, um, but, um, but, um...\n",
54 | " god help us all.\n",
55 | " '''"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": 4,
61 | "metadata": {},
62 | "outputs": [
63 | {
64 | "data": {
65 | "text/plain": [
66 | "11"
67 | ]
68 | },
69 | "execution_count": 4,
70 | "metadata": {},
71 | "output_type": "execute_result"
72 | }
73 | ],
74 | "source": [
75 | "import re\n",
76 | "len(re.findall('[B,b]ut, um',txt ))"
77 | ]
78 | },
79 | {
80 | "cell_type": "code",
81 | "execution_count": 5,
82 | "metadata": {
83 | "collapsed": true
84 | },
85 | "outputs": [],
86 | "source": [
87 | "#1 Answer=C"
88 | ]
89 | },
90 | {
91 | "cell_type": "markdown",
92 | "metadata": {},
93 | "source": [
94 | "
"
95 | ]
96 | },
97 | {
98 | "cell_type": "code",
99 | "execution_count": 12,
100 | "metadata": {},
101 | "outputs": [
102 | {
103 | "name": "stdout",
104 | "output_type": "stream",
105 | "text": [
106 | "aaa\n",
107 | "bbb\n",
108 | "ccc\n",
109 | "ddd\n",
110 | "eee\n"
111 | ]
112 | }
113 | ],
114 | "source": [
115 | "str = \"\"\"\n",
116 | "Email_Address,Nickname,Group_Status,Join_Year\n",
117 | "aa@aaa.com,aa,Owner,2014\n",
118 | "bb@bbb.com,bb,Member,2015\n",
119 | "cc@ccc.com,cc,Member,2017\n",
120 | "dd@ddd.com,dd,Member,2016\n",
121 | "ee@eee.com,ee,Member,2020\n",
122 | "\"\"\"\n",
123 | "\n",
124 | "for i in re.finditer('([a-zA-Z]+)@([a-zA-z]+).(com)',str):\n",
125 | " print(i.group(2))\n",
126 | " \n",
127 | "#Answer C"
128 | ]
129 | },
130 | {
131 | "cell_type": "markdown",
132 | "metadata": {},
133 | "source": [
134 | "
"
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": 109,
140 | "metadata": {},
141 | "outputs": [],
142 | "source": [
143 | "temp=[]\n",
144 | "str1=\"\"\"Andy,\n",
145 | "Mandi,\n",
146 | "Sandy,\n",
147 | "Hollie,\n",
148 | "Molly,\n",
149 | "Dollie,\"\"\"\n",
150 | "for i in re.finditer(\"(i|ie)(,)\",str1):\n",
151 | " temp.append(i.group(1))\n",
152 | " "
153 | ]
154 | },
155 | {
156 | "cell_type": "code",
157 | "execution_count": 110,
158 | "metadata": {},
159 | "outputs": [
160 | {
161 | "data": {
162 | "text/plain": [
163 | "['i', 'ie', 'ie']"
164 | ]
165 | },
166 | "execution_count": 110,
167 | "metadata": {},
168 | "output_type": "execute_result"
169 | }
170 | ],
171 | "source": [
172 | "temp\n",
173 | "#answer A"
174 | ]
175 | },
176 | {
177 | "cell_type": "markdown",
178 | "metadata": {},
179 | "source": [
180 | "
"
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "execution_count": 111,
186 | "metadata": {},
187 | "outputs": [],
188 | "source": [
189 | "a=[1,2,3,4,5]\n",
190 | "b=[6,7,8,9]\n",
191 | "\n",
192 | "a.extend(b)\n",
193 | "#answer B"
194 | ]
195 | },
196 | {
197 | "cell_type": "code",
198 | "execution_count": 112,
199 | "metadata": {},
200 | "outputs": [
201 | {
202 | "data": {
203 | "text/plain": [
204 | "[1, 2, 3, 4, 5, 6, 7, 8, 9]"
205 | ]
206 | },
207 | "execution_count": 112,
208 | "metadata": {},
209 | "output_type": "execute_result"
210 | }
211 | ],
212 | "source": [
213 | "a"
214 | ]
215 | },
216 | {
217 | "cell_type": "markdown",
218 | "metadata": {},
219 | "source": [
220 | "
"
221 | ]
222 | },
223 | {
224 | "cell_type": "code",
225 | "execution_count": 118,
226 | "metadata": {},
227 | "outputs": [],
228 | "source": [
229 | "import pickle as pkl\n",
230 | "pkl.dump(model,\"file\")\n",
231 | "#Answer C"
232 | ]
233 | },
234 | {
235 | "cell_type": "markdown",
236 | "metadata": {},
237 | "source": [
238 | "
"
239 | ]
240 | },
241 | {
242 | "cell_type": "code",
243 | "execution_count": 123,
244 | "metadata": {},
245 | "outputs": [],
246 | "source": [
247 | "import time\n",
248 | "str=\"21/01/2017\"\n",
249 | "dt_vale=time.strptime(str,\"%d/%m/%Y\")"
250 | ]
251 | },
252 | {
253 | "cell_type": "code",
254 | "execution_count": 124,
255 | "metadata": {},
256 | "outputs": [
257 | {
258 | "data": {
259 | "text/plain": [
260 | "time.struct_time(tm_year=2017, tm_mon=1, tm_mday=21, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=21, tm_isdst=-1)"
261 | ]
262 | },
263 | "execution_count": 124,
264 | "metadata": {},
265 | "output_type": "execute_result"
266 | }
267 | ],
268 | "source": [
269 | "dt_vale\n",
270 | "# ANSWER D"
271 | ]
272 | },
273 | {
274 | "cell_type": "markdown",
275 | "metadata": {},
276 | "source": [
277 | "
"
278 | ]
279 | },
280 | {
281 | "cell_type": "code",
282 | "execution_count": 126,
283 | "metadata": {},
284 | "outputs": [
285 | {
286 | "data": {
287 | "text/plain": [
288 | "array([[1., 0., 0.],\n",
289 | " [0., 1., 0.],\n",
290 | " [0., 0., 1.]])"
291 | ]
292 | },
293 | "execution_count": 126,
294 | "metadata": {},
295 | "output_type": "execute_result"
296 | }
297 | ],
298 | "source": [
299 | "import numpy as np\n",
300 | "np.eye(3)\n",
301 | "#Answer A"
302 | ]
303 | },
304 | {
305 | "cell_type": "markdown",
306 | "metadata": {},
307 | "source": [
308 | "
"
309 | ]
310 | },
311 | {
312 | "cell_type": "code",
313 | "execution_count": 130,
314 | "metadata": {
315 | "collapsed": true
316 | },
317 | "outputs": [],
318 | "source": [
319 | "# Answer C\n"
320 | ]
321 | },
322 | {
323 | "cell_type": "markdown",
324 | "metadata": {},
325 | "source": [
326 | "
"
327 | ]
328 | },
329 | {
330 | "cell_type": "code",
331 | "execution_count": 132,
332 | "metadata": {
333 | "collapsed": true
334 | },
335 | "outputs": [],
336 | "source": [
337 | "train_set = np.array([1, 2, 3])\n",
338 | "test_set = np.array([[0, 1, 2], [1, 2, 3]])"
339 | ]
340 | },
341 | {
342 | "cell_type": "code",
343 | "execution_count": 135,
344 | "metadata": {},
345 | "outputs": [],
346 | "source": [
347 | "resulting_set=np.vstack([train_set,test_set])"
348 | ]
349 | },
350 | {
351 | "cell_type": "code",
352 | "execution_count": 136,
353 | "metadata": {},
354 | "outputs": [
355 | {
356 | "data": {
357 | "text/plain": [
358 | "array([[1, 2, 3],\n",
359 | " [0, 1, 2],\n",
360 | " [1, 2, 3]])"
361 | ]
362 | },
363 | "execution_count": 136,
364 | "metadata": {},
365 | "output_type": "execute_result"
366 | }
367 | ],
368 | "source": [
369 | "resulting_set"
370 | ]
371 | },
372 | {
373 | "cell_type": "code",
374 | "execution_count": 137,
375 | "metadata": {
376 | "collapsed": true
377 | },
378 | "outputs": [],
379 | "source": [
380 | "#Answer--> C"
381 | ]
382 | },
383 | {
384 | "cell_type": "code",
385 | "execution_count": null,
386 | "metadata": {
387 | "collapsed": true
388 | },
389 | "outputs": [],
390 | "source": []
391 | }
392 | ],
393 | "metadata": {
394 | "kernelspec": {
395 | "display_name": "Python 3",
396 | "language": "python",
397 | "name": "python3"
398 | },
399 | "language_info": {
400 | "codemirror_mode": {
401 | "name": "ipython",
402 | "version": 3
403 | },
404 | "file_extension": ".py",
405 | "mimetype": "text/x-python",
406 | "name": "python",
407 | "nbconvert_exporter": "python",
408 | "pygments_lexer": "ipython3",
409 | "version": "3.6.8"
410 | }
411 | },
412 | "nbformat": 4,
413 | "nbformat_minor": 2
414 | }
415 |
--------------------------------------------------------------------------------
/output_based_questions/day16.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | " Output Based Questions
\n",
8 | "\n",
9 | "
"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": 1,
15 | "metadata": {
16 | "collapsed": true
17 | },
18 | "outputs": [],
19 | "source": [
20 | "#Answer new_df = pd.concat([df]*30, ignore_index=True)\n",
21 | "#Option B is correct"
22 | ]
23 | },
24 | {
25 | "cell_type": "markdown",
26 | "metadata": {},
27 | "source": [
28 | "
"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": 1,
34 | "metadata": {},
35 | "outputs": [
36 | {
37 | "name": "stderr",
38 | "output_type": "stream",
39 | "text": [
40 | "/home/shashank/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
41 | " return f(*args, **kwds)\n",
42 | "/home/shashank/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
43 | " return f(*args, **kwds)\n",
44 | "/home/shashank/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
45 | " return f(*args, **kwds)\n"
46 | ]
47 | }
48 | ],
49 | "source": [
50 | "import pandas as pd\n",
51 | "df=pd.DataFrame({'Click_id':['A','B','C','D','E'],'Count':[100,200,300,400,250]})"
52 | ]
53 | },
54 | {
55 | "cell_type": "code",
56 | "execution_count": 3,
57 | "metadata": {},
58 | "outputs": [
59 | {
60 | "data": {
61 | "text/html": [
62 | "\n",
63 | "\n",
76 | "
\n",
77 | " \n",
78 | " \n",
79 | " | \n",
80 | " Click_id | \n",
81 | " Click_count | \n",
82 | "
\n",
83 | " \n",
84 | " \n",
85 | " \n",
86 | " 0 | \n",
87 | " A | \n",
88 | " 100 | \n",
89 | "
\n",
90 | " \n",
91 | " 1 | \n",
92 | " B | \n",
93 | " 200 | \n",
94 | "
\n",
95 | " \n",
96 | " 2 | \n",
97 | " C | \n",
98 | " 300 | \n",
99 | "
\n",
100 | " \n",
101 | " 3 | \n",
102 | " D | \n",
103 | " 400 | \n",
104 | "
\n",
105 | " \n",
106 | " 4 | \n",
107 | " E | \n",
108 | " 250 | \n",
109 | "
\n",
110 | " \n",
111 | "
\n",
112 | "
"
113 | ],
114 | "text/plain": [
115 | " Click_id Click_count\n",
116 | "0 A 100\n",
117 | "1 B 200\n",
118 | "2 C 300\n",
119 | "3 D 400\n",
120 | "4 E 250"
121 | ]
122 | },
123 | "execution_count": 3,
124 | "metadata": {},
125 | "output_type": "execute_result"
126 | }
127 | ],
128 | "source": [
129 | "df.rename(columns={'Count':'Click_count'})"
130 | ]
131 | },
132 | {
133 | "cell_type": "code",
134 | "execution_count": 4,
135 | "metadata": {},
136 | "outputs": [
137 | {
138 | "data": {
139 | "text/plain": [
140 | "Index(['Click_id', 'Count'], dtype='object')"
141 | ]
142 | },
143 | "execution_count": 4,
144 | "metadata": {},
145 | "output_type": "execute_result"
146 | }
147 | ],
148 | "source": [
149 | "df.columns\n"
150 | ]
151 | },
152 | {
153 | "cell_type": "code",
154 | "execution_count": 5,
155 | "metadata": {
156 | "collapsed": true
157 | },
158 | "outputs": [],
159 | "source": [
160 | "# Answer B"
161 | ]
162 | },
163 | {
164 | "cell_type": "markdown",
165 | "metadata": {},
166 | "source": [
167 | "
"
168 | ]
169 | },
170 | {
171 | "cell_type": "code",
172 | "execution_count": 3,
173 | "metadata": {},
174 | "outputs": [
175 | {
176 | "data": {
177 | "text/plain": [
178 | "{'A': 100, 'B': 200, 'C': 300, 'D': 400, 'E': 250}"
179 | ]
180 | },
181 | "execution_count": 3,
182 | "metadata": {},
183 | "output_type": "execute_result"
184 | }
185 | ],
186 | "source": [
187 | "df=pd.DataFrame({'Click_Id':['A','B','C','D','E'],'Count':[100,200,300,400,250]})\n",
188 | "df.set_index(\"Click_Id\")['Count'].to_dict()"
189 | ]
190 | },
191 | {
192 | "cell_type": "code",
193 | "execution_count": 7,
194 | "metadata": {
195 | "collapsed": true
196 | },
197 | "outputs": [],
198 | "source": [
199 | "#Answer A"
200 | ]
201 | },
202 | {
203 | "cell_type": "markdown",
204 | "metadata": {},
205 | "source": [
206 | "
"
207 | ]
208 | },
209 | {
210 | "cell_type": "code",
211 | "execution_count": 9,
212 | "metadata": {
213 | "collapsed": true
214 | },
215 | "outputs": [],
216 | "source": [
217 | "df1=df\n",
218 | "\n",
219 | "df.loc[df.Click_id=='A','Count']+=100"
220 | ]
221 | },
222 | {
223 | "cell_type": "code",
224 | "execution_count": 10,
225 | "metadata": {},
226 | "outputs": [
227 | {
228 | "name": "stdout",
229 | "output_type": "stream",
230 | "text": [
231 | "[200 200 300 400 250] [200 200 300 400 250]\n"
232 | ]
233 | }
234 | ],
235 | "source": [
236 | "print(df.Count.values,df.Count.values)\n"
237 | ]
238 | },
239 | {
240 | "cell_type": "code",
241 | "execution_count": 11,
242 | "metadata": {
243 | "collapsed": true
244 | },
245 | "outputs": [],
246 | "source": [
247 | "# Answer A"
248 | ]
249 | },
250 | {
251 | "cell_type": "markdown",
252 | "metadata": {},
253 | "source": [
254 | "
"
255 | ]
256 | },
257 | {
258 | "cell_type": "code",
259 | "execution_count": 12,
260 | "metadata": {
261 | "collapsed": true
262 | },
263 | "outputs": [],
264 | "source": [
265 | "# Answers 1,2 &3"
266 | ]
267 | },
268 | {
269 | "cell_type": "markdown",
270 | "metadata": {},
271 | "source": [
272 | "
"
273 | ]
274 | },
275 | {
276 | "cell_type": "code",
277 | "execution_count": 13,
278 | "metadata": {
279 | "collapsed": true
280 | },
281 | "outputs": [],
282 | "source": [
283 | "#Answer --> B"
284 | ]
285 | },
286 | {
287 | "cell_type": "markdown",
288 | "metadata": {},
289 | "source": [
290 | "
"
291 | ]
292 | },
293 | {
294 | "cell_type": "code",
295 | "execution_count": 14,
296 | "metadata": {
297 | "collapsed": true
298 | },
299 | "outputs": [],
300 | "source": [
301 | "# Answer A as it is a stacked bar chart"
302 | ]
303 | },
304 | {
305 | "cell_type": "code",
306 | "execution_count": null,
307 | "metadata": {
308 | "collapsed": true
309 | },
310 | "outputs": [],
311 | "source": []
312 | }
313 | ],
314 | "metadata": {
315 | "kernelspec": {
316 | "display_name": "Python 3",
317 | "language": "python",
318 | "name": "python3"
319 | },
320 | "language_info": {
321 | "codemirror_mode": {
322 | "name": "ipython",
323 | "version": 3
324 | },
325 | "file_extension": ".py",
326 | "mimetype": "text/x-python",
327 | "name": "python",
328 | "nbconvert_exporter": "python",
329 | "pygments_lexer": "ipython3",
330 | "version": "3.6.8"
331 | }
332 | },
333 | "nbformat": 4,
334 | "nbformat_minor": 2
335 | }
336 |
--------------------------------------------------------------------------------
/output_based_questions/day9.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# OUTPUT QUESTIONS\n",
8 | "\n",
9 | "## DAY 9\n",
10 | "\n"
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {},
16 | "source": [
17 | "
"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": 1,
23 | "metadata": {},
24 | "outputs": [
25 | {
26 | "name": "stdout",
27 | "output_type": "stream",
28 | "text": [
29 | "[1, 3, 5, 7, 9]\n"
30 | ]
31 | }
32 | ],
33 | "source": [
34 | "#1\n",
35 | "a=[1,2,3,4,5,6,7,8,9]\n",
36 | "print(a[::2])"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": 2,
42 | "metadata": {},
43 | "outputs": [
44 | {
45 | "ename": "ValueError",
46 | "evalue": "attempt to assign sequence of size 6 to extended slice of size 5",
47 | "output_type": "error",
48 | "traceback": [
49 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
50 | "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
51 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m#2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m30\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m40\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m50\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m60\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
52 | "\u001b[0;31mValueError\u001b[0m: attempt to assign sequence of size 6 to extended slice of size 5"
53 | ]
54 | }
55 | ],
56 | "source": [
57 | "#2\n",
58 | "a[::2]=10,20,30,40,50,60\n",
59 | "print(a)"
60 | ]
61 | },
62 | {
63 | "cell_type": "markdown",
64 | "metadata": {},
65 | "source": [
66 | "
"
67 | ]
68 | },
69 | {
70 | "cell_type": "code",
71 | "execution_count": 3,
72 | "metadata": {},
73 | "outputs": [
74 | {
75 | "data": {
76 | "text/plain": [
77 | "[4, 3, 2]"
78 | ]
79 | },
80 | "execution_count": 3,
81 | "metadata": {},
82 | "output_type": "execute_result"
83 | }
84 | ],
85 | "source": [
86 | "#3\n",
87 | "a=[1,2,3,4,5]\n",
88 | "a[3:0:-1]"
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": 5,
94 | "metadata": {},
95 | "outputs": [
96 | {
97 | "name": "stdout",
98 | "output_type": "stream",
99 | "text": [
100 | "3 44\n"
101 | ]
102 | }
103 | ],
104 | "source": [
105 | "#4\n",
106 | "def f(value,values):\n",
107 | " v=1\n",
108 | " values[0]=44\n",
109 | "\n",
110 | "t=3\n",
111 | "v=[1,2,3]\n",
112 | "f(t,v)\n",
113 | "print(t,v[0])"
114 | ]
115 | },
116 | {
117 | "cell_type": "markdown",
118 | "metadata": {},
119 | "source": [
120 | "
"
121 | ]
122 | },
123 | {
124 | "cell_type": "code",
125 | "execution_count": 6,
126 | "metadata": {},
127 | "outputs": [
128 | {
129 | "name": "stdout",
130 | "output_type": "stream",
131 | "text": [
132 | "4\n"
133 | ]
134 | }
135 | ],
136 | "source": [
137 | "#6\n",
138 | "data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]\n",
139 | "def fun(m):\n",
140 | " v = m[0][0]\n",
141 | "\n",
142 | " for row in m:\n",
143 | " for element in row:\n",
144 | " if v < element: v = element\n",
145 | "\n",
146 | " return v\n",
147 | "print(fun(data[0]))"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": 7,
153 | "metadata": {},
154 | "outputs": [
155 | {
156 | "name": "stdout",
157 | "output_type": "stream",
158 | "text": [
159 | "4\n",
160 | "7\n",
161 | "11\n",
162 | "15\n"
163 | ]
164 | }
165 | ],
166 | "source": [
167 | "#7\n",
168 | "arr = [[1, 2, 3, 4],\n",
169 | " [4, 5, 6, 7],\n",
170 | " [8, 9, 10, 11],\n",
171 | " [12, 13, 14, 15]]\n",
172 | "for i in range(0, 4):\n",
173 | " print(arr[i].pop())"
174 | ]
175 | },
176 | {
177 | "cell_type": "markdown",
178 | "metadata": {},
179 | "source": [
180 | "
"
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "execution_count": 10,
186 | "metadata": {},
187 | "outputs": [
188 | {
189 | "name": "stdout",
190 | "output_type": "stream",
191 | "text": [
192 | "[1]\n",
193 | "[1, 2]\n",
194 | "[1, 2, 3]\n"
195 | ]
196 | },
197 | {
198 | "data": {
199 | "text/plain": [
200 | "[1, 2, 3]"
201 | ]
202 | },
203 | "execution_count": 10,
204 | "metadata": {},
205 | "output_type": "execute_result"
206 | }
207 | ],
208 | "source": [
209 | "#8\n",
210 | "def f(i, values = []):\n",
211 | " values.append(i)\n",
212 | " print (values)\n",
213 | " return values\n",
214 | "f(1)\n",
215 | "f(2)\n",
216 | "f(3)"
217 | ]
218 | },
219 | {
220 | "cell_type": "code",
221 | "execution_count": 11,
222 | "metadata": {},
223 | "outputs": [
224 | {
225 | "name": "stdout",
226 | "output_type": "stream",
227 | "text": [
228 | "2 3 4 5 6 6 "
229 | ]
230 | }
231 | ],
232 | "source": [
233 | "#9\n",
234 | "arr = [1, 2, 3, 4, 5, 6]\n",
235 | "for i in range(1, 6):\n",
236 | " arr[i - 1] = arr[i]\n",
237 | "for i in range(0, 6): \n",
238 | " print(arr[i], end = \" \")"
239 | ]
240 | },
241 | {
242 | "cell_type": "markdown",
243 | "metadata": {},
244 | "source": [
245 | "
"
246 | ]
247 | },
248 | {
249 | "cell_type": "code",
250 | "execution_count": 12,
251 | "metadata": {},
252 | "outputs": [
253 | {
254 | "name": "stdout",
255 | "output_type": "stream",
256 | "text": [
257 | "22\n"
258 | ]
259 | }
260 | ],
261 | "source": [
262 | "fruit_list1 = ['Apple', 'Berry', 'Cherry', 'Papaya']\n",
263 | "fruit_list2 = fruit_list1\n",
264 | "fruit_list3 = fruit_list1[:]\n",
265 | "\n",
266 | "fruit_list2[0] = 'Guava'\n",
267 | "fruit_list3[1] = 'Kiwi'\n",
268 | "\n",
269 | "sum = 0\n",
270 | "for ls in (fruit_list1, fruit_list2, fruit_list3):\n",
271 | " if ls[0] == 'Guava':\n",
272 | " sum += 1\n",
273 | " if ls[1] == 'Kiwi':\n",
274 | " sum += 20\n",
275 | "\n",
276 | "print (sum)"
277 | ]
278 | },
279 | {
280 | "cell_type": "code",
281 | "execution_count": null,
282 | "metadata": {
283 | "collapsed": true
284 | },
285 | "outputs": [],
286 | "source": []
287 | }
288 | ],
289 | "metadata": {
290 | "kernelspec": {
291 | "display_name": "Python 3",
292 | "language": "python",
293 | "name": "python3"
294 | },
295 | "language_info": {
296 | "codemirror_mode": {
297 | "name": "ipython",
298 | "version": 3
299 | },
300 | "file_extension": ".py",
301 | "mimetype": "text/x-python",
302 | "name": "python",
303 | "nbconvert_exporter": "python",
304 | "pygments_lexer": "ipython3",
305 | "version": "3.6.8"
306 | }
307 | },
308 | "nbformat": 4,
309 | "nbformat_minor": 2
310 | }
311 |
--------------------------------------------------------------------------------
/output_based_questions/images/day10_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day10_1.png
--------------------------------------------------------------------------------
/output_based_questions/images/day10_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day10_2.png
--------------------------------------------------------------------------------
/output_based_questions/images/day10_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day10_3.png
--------------------------------------------------------------------------------
/output_based_questions/images/day10_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day10_4.png
--------------------------------------------------------------------------------
/output_based_questions/images/day11_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day11_1.png
--------------------------------------------------------------------------------
/output_based_questions/images/day11_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day11_2.png
--------------------------------------------------------------------------------
/output_based_questions/images/day11_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day11_3.png
--------------------------------------------------------------------------------
/output_based_questions/images/day11_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day11_4.png
--------------------------------------------------------------------------------
/output_based_questions/images/day12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day12.png
--------------------------------------------------------------------------------
/output_based_questions/images/day12_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day12_2.png
--------------------------------------------------------------------------------
/output_based_questions/images/day12_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day12_3.png
--------------------------------------------------------------------------------
/output_based_questions/images/day13_1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day13_1.PNG
--------------------------------------------------------------------------------
/output_based_questions/images/day13_2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day13_2.PNG
--------------------------------------------------------------------------------
/output_based_questions/images/day13_3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day13_3.PNG
--------------------------------------------------------------------------------
/output_based_questions/images/day14_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_1.png
--------------------------------------------------------------------------------
/output_based_questions/images/day14_10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_10.png
--------------------------------------------------------------------------------
/output_based_questions/images/day14_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_2.png
--------------------------------------------------------------------------------
/output_based_questions/images/day14_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_3.png
--------------------------------------------------------------------------------
/output_based_questions/images/day14_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_4.png
--------------------------------------------------------------------------------
/output_based_questions/images/day14_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_5.png
--------------------------------------------------------------------------------
/output_based_questions/images/day14_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_6.png
--------------------------------------------------------------------------------
/output_based_questions/images/day14_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_7.png
--------------------------------------------------------------------------------
/output_based_questions/images/day14_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_8.png
--------------------------------------------------------------------------------
/output_based_questions/images/day14_9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day14_9.png
--------------------------------------------------------------------------------
/output_based_questions/images/day15_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day15_1.png
--------------------------------------------------------------------------------
/output_based_questions/images/day15_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day15_2.png
--------------------------------------------------------------------------------
/output_based_questions/images/day15_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day15_3.png
--------------------------------------------------------------------------------
/output_based_questions/images/day15_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day15_4.png
--------------------------------------------------------------------------------
/output_based_questions/images/day15_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day15_5.png
--------------------------------------------------------------------------------
/output_based_questions/images/day15_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day15_6.png
--------------------------------------------------------------------------------
/output_based_questions/images/day16_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day16_1.png
--------------------------------------------------------------------------------
/output_based_questions/images/day16_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day16_2.png
--------------------------------------------------------------------------------
/output_based_questions/images/day16_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day16_3.png
--------------------------------------------------------------------------------
/output_based_questions/images/day16_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day16_4.png
--------------------------------------------------------------------------------
/output_based_questions/images/day16_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day16_5.png
--------------------------------------------------------------------------------
/output_based_questions/images/day16_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day16_6.png
--------------------------------------------------------------------------------
/output_based_questions/images/day16_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day16_7.png
--------------------------------------------------------------------------------
/output_based_questions/images/day9_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day9_1.png
--------------------------------------------------------------------------------
/output_based_questions/images/day9_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day9_2.png
--------------------------------------------------------------------------------
/output_based_questions/images/day9_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day9_3.png
--------------------------------------------------------------------------------
/output_based_questions/images/day9_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day9_4.png
--------------------------------------------------------------------------------
/output_based_questions/images/day9_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/output_based_questions/images/day9_5.png
--------------------------------------------------------------------------------
/pandas/Automobile_data.csv:
--------------------------------------------------------------------------------
1 | ,index,company,body-style,wheel-base,length,engine-type,num-of-cylinders,horsepower,average-mileage,price
2 | 0,0,alfa-romero,convertible,88.6,168.8,dohc,four,111,21,13495.0
3 | 1,1,alfa-romero,convertible,88.6,168.8,dohc,four,111,21,16500.0
4 | 2,2,alfa-romero,hatchback,94.5,171.2,ohcv,six,154,19,16500.0
5 | 3,3,audi,sedan,99.8,176.6,ohc,four,102,24,13950.0
6 | 4,4,audi,sedan,99.4,176.6,ohc,five,115,18,17450.0
7 | 5,5,audi,sedan,99.8,177.3,ohc,five,110,19,15250.0
8 | 6,6,audi,wagon,105.8,192.7,ohc,five,110,19,18920.0
9 | 7,9,bmw,sedan,101.2,176.8,ohc,four,101,23,16430.0
10 | 8,10,bmw,sedan,101.2,176.8,ohc,four,101,23,16925.0
11 | 9,11,bmw,sedan,101.2,176.8,ohc,six,121,21,20970.0
12 | 10,13,bmw,sedan,103.5,189.0,ohc,six,182,16,30760.0
13 | 11,14,bmw,sedan,103.5,193.8,ohc,six,182,16,41315.0
14 | 12,15,bmw,sedan,110.0,197.0,ohc,six,182,15,36880.0
15 | 13,16,chevrolet,hatchback,88.4,141.1,l,three,48,47,5151.0
16 | 14,17,chevrolet,hatchback,94.5,155.9,ohc,four,70,38,6295.0
17 | 15,18,chevrolet,sedan,94.5,158.8,ohc,four,70,38,6575.0
18 | 16,19,dodge,hatchback,93.7,157.3,ohc,four,68,31,6377.0
19 | 17,20,dodge,hatchback,93.7,157.3,ohc,four,68,31,6229.0
20 | 18,27,honda,wagon,96.5,157.1,ohc,four,76,30,7295.0
21 | 19,28,honda,sedan,96.5,175.4,ohc,four,101,24,12945.0
22 | 20,29,honda,sedan,96.5,169.1,ohc,four,100,25,10345.0
23 | 21,30,isuzu,sedan,94.3,170.7,ohc,four,78,24,6785.0
24 | 22,31,isuzu,sedan,94.5,155.9,ohc,four,70,38,
25 | 23,32,isuzu,sedan,94.5,155.9,ohc,four,70,38,
26 | 24,33,jaguar,sedan,113.0,199.6,dohc,six,176,15,32250.0
27 | 25,34,jaguar,sedan,113.0,199.6,dohc,six,176,15,35550.0
28 | 26,35,jaguar,sedan,102.0,191.7,ohcv,twelve,262,13,36000.0
29 | 27,36,mazda,hatchback,93.1,159.1,ohc,four,68,30,5195.0
30 | 28,37,mazda,hatchback,93.1,159.1,ohc,four,68,31,6095.0
31 | 29,38,mazda,hatchback,93.1,159.1,ohc,four,68,31,6795.0
32 | 30,39,mazda,hatchback,95.3,169.0,rotor,two,101,17,11845.0
33 | 31,43,mazda,sedan,104.9,175.0,ohc,four,72,31,18344.0
34 | 32,44,mercedes-benz,sedan,110.0,190.9,ohc,five,123,22,25552.0
35 | 33,45,mercedes-benz,wagon,110.0,190.9,ohc,five,123,22,28248.0
36 | 34,46,mercedes-benz,sedan,120.9,208.1,ohcv,eight,184,14,40960.0
37 | 35,47,mercedes-benz,hardtop,112.0,199.2,ohcv,eight,184,14,45400.0
38 | 36,49,mitsubishi,hatchback,93.7,157.3,ohc,four,68,37,5389.0
39 | 37,50,mitsubishi,hatchback,93.7,157.3,ohc,four,68,31,6189.0
40 | 38,51,mitsubishi,sedan,96.3,172.4,ohc,four,88,25,6989.0
41 | 39,52,mitsubishi,sedan,96.3,172.4,ohc,four,88,25,8189.0
42 | 40,53,nissan,sedan,94.5,165.3,ohc,four,55,45,7099.0
43 | 41,54,nissan,sedan,94.5,165.3,ohc,four,69,31,6649.0
44 | 42,55,nissan,sedan,94.5,165.3,ohc,four,69,31,6849.0
45 | 43,56,nissan,wagon,94.5,170.2,ohc,four,69,31,7349.0
46 | 44,57,nissan,sedan,100.4,184.6,ohcv,six,152,19,13499.0
47 | 45,61,porsche,hardtop,89.5,168.9,ohcf,six,207,17,34028.0
48 | 46,62,porsche,convertible,89.5,168.9,ohcf,six,207,17,37028.0
49 | 47,63,porsche,hatchback,98.4,175.7,dohcv,eight,288,17,
50 | 48,66,toyota,hatchback,95.7,158.7,ohc,four,62,35,5348.0
51 | 49,67,toyota,hatchback,95.7,158.7,ohc,four,62,31,6338.0
52 | 50,68,toyota,hatchback,95.7,158.7,ohc,four,62,31,6488.0
53 | 51,69,toyota,wagon,95.7,169.7,ohc,four,62,31,6918.0
54 | 52,70,toyota,wagon,95.7,169.7,ohc,four,62,27,7898.0
55 | 53,71,toyota,wagon,95.7,169.7,ohc,four,62,27,8778.0
56 | 54,79,toyota,wagon,104.5,187.8,dohc,six,156,19,15750.0
57 | 55,80,volkswagen,sedan,97.3,171.7,ohc,four,52,37,7775.0
58 | 56,81,volkswagen,sedan,97.3,171.7,ohc,four,85,27,7975.0
59 | 57,82,volkswagen,sedan,97.3,171.7,ohc,four,52,37,7995.0
60 | 58,86,volkswagen,sedan,97.3,171.7,ohc,four,100,26,9995.0
61 | 59,87,volvo,sedan,104.3,188.8,ohc,four,114,23,12940.0
62 | 60,88,volvo,wagon,104.3,188.8,ohc,four,114,23,13415.0
63 |
--------------------------------------------------------------------------------
/pandas/images/day17_1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_1.PNG
--------------------------------------------------------------------------------
/pandas/images/day17_10.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_10.PNG
--------------------------------------------------------------------------------
/pandas/images/day17_2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_2.PNG
--------------------------------------------------------------------------------
/pandas/images/day17_3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_3.PNG
--------------------------------------------------------------------------------
/pandas/images/day17_4.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_4.PNG
--------------------------------------------------------------------------------
/pandas/images/day17_5.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_5.PNG
--------------------------------------------------------------------------------
/pandas/images/day17_6.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_6.PNG
--------------------------------------------------------------------------------
/pandas/images/day17_7.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_7.PNG
--------------------------------------------------------------------------------
/pandas/images/day17_8.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_8.PNG
--------------------------------------------------------------------------------
/pandas/images/day17_9.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day17_9.PNG
--------------------------------------------------------------------------------
/pandas/images/day18_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day18_1.png
--------------------------------------------------------------------------------
/pandas/images/day18_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day18_2.png
--------------------------------------------------------------------------------
/pandas/images/day18_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day18_3.png
--------------------------------------------------------------------------------
/pandas/images/day18_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashankjain12/Udaquest/6e504376e53aed15f7ea26d00e80b230fa080396/pandas/images/day18_4.png
--------------------------------------------------------------------------------