Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 75af943

Browse files
author
Amogh Singhal
authored
Add files via upload
1 parent 2066f00 commit 75af943

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

‎bits_wilp/Ex2_Numpy_Q2.ipynb‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "e572d5e4-94a8-4059-bc1f-332e713b02e3",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import numpy as np\n",
11+
"import pandas as pd"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"id": "b525ea5a-5f30-40ac-a98c-40394d788bba",
17+
"metadata": {},
18+
"source": [
19+
"### Set Difference Between Two Nupmy Arrays"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 7,
25+
"id": "bdb7936b-b56f-458e-9e72-70eeb7968190",
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"# Function to take input array from user\n",
30+
"def np_array_frm_input(prompt):\n",
31+
" try:\n",
32+
" arr = list(map(int, input(prompt).split()))\n",
33+
" np_array = np.array(arr, dtype=int)\n",
34+
" except ValueError as e:\n",
35+
" np_array = None\n",
36+
" print(\"ERROR: Please enter only integers !!!\")\n",
37+
" print(e)\n",
38+
" return np_array"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 17,
44+
"id": "1654ed7a-63f9-44bf-a30e-ea85ecd806fd",
45+
"metadata": {},
46+
"outputs": [
47+
{
48+
"name": "stdin",
49+
"output_type": "stream",
50+
"text": [
51+
"\n",
52+
"Enter numbers for first sequence: 6 4 2\n",
53+
"\n",
54+
"Enter numbers for second sequence: 3 4\n"
55+
]
56+
},
57+
{
58+
"name": "stdout",
59+
"output_type": "stream",
60+
"text": [
61+
"\n",
62+
"The set difference between [6 4 2] and [3 4] is [2 6]\n"
63+
]
64+
}
65+
],
66+
"source": [
67+
"# Return the sorted, unique values in array1 that are not in array2\n",
68+
"np_arr1 = np_array_frm_input(\"\\nEnter numbers for first sequence: \")\n",
69+
"np_arr2 = np_array_frm_input(\"\\nEnter numbers for second sequence: \")\n",
70+
"print(f\"\\nThe set difference between {np_arr1} and {np_arr2} is {np.setdiff1d(np_arr1, np_arr2)}\")"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": 4,
76+
"id": "79d06c1a-d66e-4b97-8de4-4332b51d3220",
77+
"metadata": {},
78+
"outputs": [
79+
{
80+
"data": {
81+
"text/plain": [
82+
"array([2])"
83+
]
84+
},
85+
"execution_count": 4,
86+
"metadata": {},
87+
"output_type": "execute_result"
88+
}
89+
],
90+
"source": []
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"id": "a917ffd2-be2c-4e04-82bf-f8a2209ea340",
96+
"metadata": {},
97+
"outputs": [],
98+
"source": []
99+
}
100+
],
101+
"metadata": {
102+
"kernelspec": {
103+
"display_name": "Python 3",
104+
"language": "python",
105+
"name": "python3"
106+
},
107+
"language_info": {
108+
"codemirror_mode": {
109+
"name": "ipython",
110+
"version": 3
111+
},
112+
"file_extension": ".py",
113+
"mimetype": "text/x-python",
114+
"name": "python",
115+
"nbconvert_exporter": "python",
116+
"pygments_lexer": "ipython3",
117+
"version": "3.8.5"
118+
}
119+
},
120+
"nbformat": 4,
121+
"nbformat_minor": 5
122+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /