• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Aug 22nd, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. {
2.  "cells": [
3.   {
4.    "cell_type": "markdown",
6.    "source": [
7.     "Python Notebook 1: Reviewing Numpy (1D)"
8.    ]
9.   },
10.   {
11.    "cell_type": "code",
12.    "execution_count": 25,
14.    "outputs": [],
15.    "source": [
16.     "import numpy as np"
17.    ]
18.   },
19.   {
20.    "cell_type": "code",
21.    "execution_count": 26,
23.    "outputs": [],
24.    "source": [
25.     "a=np.array([1,2,3])"
26.    ]
27.   },
28.   {
29.    "cell_type": "code",
30.    "execution_count": 27,
32.    "outputs": [],
33.    "source": [
34.     "b=np.array([2,3,4])"
35.    ]
36.   },
37.   {
38.    "cell_type": "code",
39.    "execution_count": 28,
41.    "outputs": [
42.     {
43.      "data": {
44.       "text/plain": [
45.        "array([ 2,  3, -5])"
46.       ]
47.      },
48.      "execution_count": 28,
50.      "output_type": "execute_result"
51.     }
52.    ],
53.    "source": [
54.     "b[2]=-5\n",
55.     "b"
56.    ]
57.   },
58.   {
59.    "cell_type": "code",
60.    "execution_count": 29,
62.    "outputs": [
63.     {
64.      "data": {
65.       "text/plain": [
66.        "0.0"
67.       ]
68.      },
69.      "execution_count": 29,
71.      "output_type": "execute_result"
72.     }
73.    ],
74.    "source": [
75.     "mean=b.mean()\n",
76.     "mean"
77.    ]
78.   },
79.   {
80.    "cell_type": "code",
81.    "execution_count": 30,
83.    "outputs": [
84.     {
85.      "data": {
86.       "text/plain": [
87.        "3.559026084010437"
88.       ]
89.      },
90.      "execution_count": 30,
92.      "output_type": "execute_result"
93.     }
94.    ],
95.    "source": [
96.     "std=b.std()\n",
97.     "std"
98.    ]
99.   },
100.   {
101.    "cell_type": "code",
102.    "execution_count": 31,
104.    "outputs": [
105.     {
106.      "data": {
107.       "text/plain": [
108.        "array([  2,   6, -15])"
109.       ]
110.      },
111.      "execution_count": 31,
113.      "output_type": "execute_result"
114.     }
115.    ],
116.    "source": [
117.     "a*b"
118.    ]
119.   },
120.   {
121.    "cell_type": "code",
122.    "execution_count": 32,
124.    "outputs": [
125.     {
126.      "data": {
127.       "text/plain": [
128.        "-7"
129.       ]
130.      },
131.      "execution_count": 32,
133.      "output_type": "execute_result"
134.     }
135.    ],
136.    "source": [
137.     "np.dot(a,b)"
138.    ]
139.   },
140.   {
141.    "cell_type": "markdown",
143.    "source": [
144.     "Plotting vectors is cool:"
145.    ]
146.   },
147.   {
148.    "cell_type": "code",
149.    "execution_count": 33,
151.    "outputs": [],
152.    "source": [
153.     "import matplotlib.pyplot as plt"
154.    ]
155.   },
156.   {
157.    "cell_type": "markdown",
159.    "source": [
160.     "got this function from IBM online course:"
161.    ]
162.   },
163.   {
164.    "cell_type": "code",
165.    "execution_count": 34,
167.    "outputs": [],
168.    "source": [
169.     "def Plotvec2(a,b):\n",
170.     "    ax = plt.axes()\n",
172.     "    plt.text(*(a + 0.1), 'a')\n",
174.     "    plt.text(*(b + 0.1), 'b')\n",
175.     "    plt.ylim(-2, 2)\n",
176.     "    plt.xlim(-2, 2)"
177.    ]
178.   },
179.   {
180.    "cell_type": "code",
181.    "execution_count": 35,
183.    "outputs": [
184.     {
185.      "data": {
187.       "text/plain": [
188.        "<Figure size 432x288 with 1 Axes>"
189.       ]
190.      },
192.       "needs_background": "light"
193.      },
194.      "output_type": "display_data"
195.     }
196.    ],
197.    "source": [
198.     "a=np.array([1,0])\n",
199.     "b=np.array([0,1])\n",
200.     "Plotvec2(a,b)"
201.    ]
202.   },
203.   {
204.    "cell_type": "markdown",
206.    "source": [
207.     "Of course we will see that the dot product of these two vectors is zero, as they are orthogonal:"
208.    ]
209.   },
210.   {
211.    "cell_type": "code",
212.    "execution_count": 36,
214.    "outputs": [
215.     {
216.      "data": {
217.       "text/plain": [
218.        "0"
219.       ]
220.      },
221.      "execution_count": 36,
223.      "output_type": "execute_result"
224.     }
225.    ],
226.    "source": [
227.     "np.dot(a,b)"
228.    ]
229.   },
230.   {
231.    "cell_type": "markdown",
233.    "source": [
234.     "Once final cool thing is generating an array using the np function \"linspace\""
235.    ]
236.   },
237.   {
238.    "cell_type": "code",
239.    "execution_count": 39,
241.    "outputs": [
242.     {
243.      "data": {
244.       "text/plain": [
245.        "array([11. , 12.5, 14. , 15.5, 17. ])"
246.       ]
247.      },
248.      "execution_count": 39,
250.      "output_type": "execute_result"
251.     }
252.    ],
253.    "source": [
254.     "c=np.linspace(11,17,5)\n",
255.     "c"
256.    ]
257.   },
258.   {
259.    "cell_type": "code",
260.    "execution_count": 40,
262.    "outputs": [
263.     {
264.      "data": {
265.       "text/plain": [
266.        "numpy.ndarray"
267.       ]
268.      },
269.      "execution_count": 40,
271.      "output_type": "execute_result"
272.     }
273.    ],
274.    "source": [
275.     "type(c)"
276.    ]
277.   },
278.   {
279.    "cell_type": "code",
280.    "execution_count": 41,
282.    "outputs": [],
283.    "source": [
284.     "d=np.linspace(-5,5,200)"
285.    ]
286.   },
287.   {
288.    "cell_type": "code",
289.    "execution_count": 43,
291.    "outputs": [],
292.    "source": [
293.     "e=d**3"
294.    ]
295.   },
296.   {
297.    "cell_type": "code",
298.    "execution_count": 44,
300.    "outputs": [
301.     {
302.      "data": {
303.       "text/plain": [
304.        "[<matplotlib.lines.Line2D at 0x7f0741bbc5f8>]"
305.       ]
306.      },
307.      "execution_count": 44,
309.      "output_type": "execute_result"
310.     },
311.     {
312.      "data": {
314.       "text/plain": [
315.        "<Figure size 432x288 with 1 Axes>"
316.       ]
317.      },
319.       "needs_background": "light"
320.      },
321.      "output_type": "display_data"
322.     }
323.    ],
324.    "source": [
325.     "plt.plot(d,e)"
326.    ]
327.   },
328.   {
329.    "cell_type": "code",
330.    "execution_count": null,
332.    "outputs": [],
333.    "source": []
334.   }
335.  ],
337.   "kernelspec": {
338.    "display_name": "Python",
339.    "language": "python",
340.    "name": "conda-env-python-py"
341.   },
342.   "language_info": {
343.    "codemirror_mode": {
344.     "name": "ipython",
345.     "version": 3
346.    },
347.    "file_extension": ".py",
348.    "mimetype": "text/x-python",
349.    "name": "python",
350.    "nbconvert_exporter": "python",
351.    "pygments_lexer": "ipython3",
352.    "version": "3.6.7"
353.   }
354.  },
355.  "nbformat": 4,
356.  "nbformat_minor": 4
357. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top