Skip to content

Commit a6ece7f

Browse files
committed
numpy
1 parent b160934 commit a6ece7f

4 files changed

Lines changed: 233 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 5
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 5
6+
}

Untitled.ipynb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "b199e8fd",
6+
"metadata": {},
7+
"source": [
8+
"# BINARY SEARCH"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "df14691f",
14+
"metadata": {},
15+
"source": [
16+
"### Alice has some cards with numbers written on them . she arranges the cards in decreasing order and lays them out face down in a sequence on a table . she challenges Bob to pick out the card containing a given number by turning over a s few cards as possible. write a function to help Bob locate the card."
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"id": "ee8d6a0e",
22+
"metadata": {},
23+
"source": [
24+
"####inputs\n",
25+
"cards: a list of numbers sorted in decreasing order eg [12, 11, 10, 6, 4, 3, 2]\n",
26+
"query: a number whose position in the array will be determined"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"id": "1d46a3ce",
32+
"metadata": {},
33+
"source": [
34+
"####output\n",
35+
"position: the position of the query in the list cards"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": null,
41+
"id": "d51d9758",
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"def locate_card(cards, query):\n",
46+
" pass"
47+
]
48+
}
49+
],
50+
"metadata": {
51+
"kernelspec": {
52+
"display_name": "Python 3 (ipykernel)",
53+
"language": "python",
54+
"name": "python3"
55+
},
56+
"language_info": {
57+
"codemirror_mode": {
58+
"name": "ipython",
59+
"version": 3
60+
},
61+
"file_extension": ".py",
62+
"mimetype": "text/x-python",
63+
"name": "python",
64+
"nbconvert_exporter": "python",
65+
"pygments_lexer": "ipython3",
66+
"version": "3.9.5"
67+
}
68+
},
69+
"nbformat": 4,
70+
"nbformat_minor": 5
71+
}

trig funcs.ipynb

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 5,
6+
"id": "90a55051",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"[0.0000000e+00 1.0000000e+00 1.2246468e-16]\n",
14+
"[ 1.000000e+00 6.123234e-17 -1.000000e+00]\n",
15+
"[ 0.00000000e+00 1.63312394e+16 -1.22464680e-16]\n"
16+
]
17+
}
18+
],
19+
"source": [
20+
"#trigonometric functions\n",
21+
"#array of angles\n",
22+
"import numpy as np\n",
23+
"theta = np.linspace(0, np.pi, 3)\n",
24+
"print(np.sin(theta))\n",
25+
"print(np.cos(theta))\n",
26+
"print(np.tan(theta))"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 6,
32+
"id": "f71d4ef4",
33+
"metadata": {},
34+
"outputs": [
35+
{
36+
"name": "stdout",
37+
"output_type": "stream",
38+
"text": [
39+
"[-1.57079633 0. 1.57079633]\n",
40+
"[3.14159265 1.57079633 0. ]\n",
41+
"[-0.78539816 0. 0.78539816]\n"
42+
]
43+
}
44+
],
45+
"source": [
46+
"#inverse trigonometry\n",
47+
"x = [-1, 0, 1]\n",
48+
"print(np.arcsin(x))\n",
49+
"print(np.arccos(x))\n",
50+
"print(np.arctan(x))"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 7,
56+
"id": "f179e021",
57+
"metadata": {},
58+
"outputs": [
59+
{
60+
"name": "stdout",
61+
"output_type": "stream",
62+
"text": [
63+
"[ 2.71828183 7.3890561 20.08553692]\n",
64+
"[2. 4. 8.]\n",
65+
"[ 3 9 27]\n"
66+
]
67+
}
68+
],
69+
"source": [
70+
"#exponentials\n",
71+
"x = [1, 2, 3]\n",
72+
"print(np.exp(x))\n",
73+
"print(np.exp2(x))\n",
74+
"print(np.power(3, x))"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": 8,
80+
"id": "3780ac89",
81+
"metadata": {},
82+
"outputs": [
83+
{
84+
"name": "stdout",
85+
"output_type": "stream",
86+
"text": [
87+
"[0. 0.69314718 1.38629436 2.30258509]\n",
88+
"[0. 1. 2. 3.32192809]\n",
89+
"[0. 0.30103 0.60205999 1. ]\n"
90+
]
91+
}
92+
],
93+
"source": [
94+
"#logarithms\n",
95+
"x = [1, 2, 4, 10]\n",
96+
"print(np.log(x))\n",
97+
"print(np.log2(x))\n",
98+
"print(np.log10(x))"
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": 9,
104+
"id": "516d9e69",
105+
"metadata": {},
106+
"outputs": [
107+
{
108+
"ename": "ModuleNotFoundError",
109+
"evalue": "No module named 'scipy'",
110+
"output_type": "error",
111+
"traceback": [
112+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
113+
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
114+
"Input \u001b[1;32mIn [9]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m#special ufuncs\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mscipy\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m special\n\u001b[0;32m 3\u001b[0m x \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m5\u001b[39m, \u001b[38;5;241m10\u001b[39m]\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(special\u001b[38;5;241m.\u001b[39mgamma(x))\n",
115+
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'scipy'"
116+
]
117+
}
118+
],
119+
"source": [
120+
"#special ufuncs\n",
121+
"from scipy import special\n",
122+
"x = [1, 5, 10]\n",
123+
"print(special.gamma(x))\n",
124+
"print(special.gammaln(x))\n",
125+
"print(special.beta(x, 2))"
126+
]
127+
}
128+
],
129+
"metadata": {
130+
"kernelspec": {
131+
"display_name": "Python 3 (ipykernel)",
132+
"language": "python",
133+
"name": "python3"
134+
},
135+
"language_info": {
136+
"codemirror_mode": {
137+
"name": "ipython",
138+
"version": 3
139+
},
140+
"file_extension": ".py",
141+
"mimetype": "text/x-python",
142+
"name": "python",
143+
"nbconvert_exporter": "python",
144+
"pygments_lexer": "ipython3",
145+
"version": "3.9.5"
146+
}
147+
},
148+
"nbformat": 4,
149+
"nbformat_minor": 5
150+
}

0 commit comments

Comments
 (0)