Skip to content

Commit 87dc6b6

Browse files
committed
Fix matplotlib and numpy imports
* Change all instances of np. to numpy. * Change all instances of plt. to pyplot. Note that this was done with a simple sed script and there may be mistakes.
1 parent 74a78ce commit 87dc6b6

17 files changed

Lines changed: 767 additions & 747 deletions

lessons/00_Quick_Python_Intro.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"collapsed": false,
4444
"input": [
4545
"#comments in python are denoted by the pound sign\n",
46-
"import numpy as np #numpy is a library we're importing that provides a bunch of useful matrix operations akin to MATLAB\n",
47-
"import matplotlib.pyplot as plt #matplotlib is 2D plotting library which we will use to plot our results"
46+
"import numpy #numpy is a library we're importing that provides a bunch of useful matrix operations akin to MATLAB\n",
47+
"from matplotlib import pyplot #matplotlib is 2D plotting library which we will use to plot our results"
4848
],
4949
"language": "python",
5050
"metadata": {},
@@ -62,7 +62,7 @@
6262
"cell_type": "code",
6363
"collapsed": false,
6464
"input": [
65-
"myarray = np.linspace(0, 5, 10)\n",
65+
"myarray = numpy.linspace(0, 5, 10)\n",
6666
"myarray"
6767
],
6868
"language": "python",
@@ -377,7 +377,7 @@
377377
"cell_type": "code",
378378
"collapsed": false,
379379
"input": [
380-
"myvals = np.array([1, 2, 3, 4, 5])\n",
380+
"myvals = numpy.array([1, 2, 3, 4, 5])\n",
381381
"myvals"
382382
],
383383
"language": "python",
@@ -500,7 +500,7 @@
500500
"cell_type": "code",
501501
"collapsed": false,
502502
"input": [
503-
"a = np.linspace(1,5,5)"
503+
"a = numpy.linspace(1,5,5)"
504504
],
505505
"language": "python",
506506
"metadata": {},
@@ -655,7 +655,7 @@
655655
"cell_type": "code",
656656
"collapsed": false,
657657
"input": [
658-
"c = np.empty_like(a)"
658+
"c = numpy.empty_like(a)"
659659
],
660660
"language": "python",
661661
"metadata": {},

lessons/01_Step_1.ipynb

Lines changed: 541 additions & 521 deletions
Large diffs are not rendered by default.

lessons/02_Step_2.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
"cell_type": "code",
7676
"collapsed": true,
7777
"input": [
78-
"import numpy as np #we're importing numpy and calling it np locally\n",
79-
"import matplotlib.pyplot as plt #and our 2D plotting library, calling it plt\n",
78+
"import numpy #we're importing numpy and calling it np locally\n",
79+
"from matplotlib import pyplot #and our 2D plotting library, calling it plt\n",
8080
"%matplotlib inline\n",
8181
"\n",
8282
"\n",
@@ -85,10 +85,10 @@
8585
"nt = 20 #nt is the number of timesteps we want to calculate\n",
8686
"dt = .025 #dt is the amount of time each timestep covers (delta t)\n",
8787
"\n",
88-
"u = np.ones(nx) #as before, we initialize u with every value equal to 1.\n",
88+
"u = numpy.ones(nx) #as before, we initialize u with every value equal to 1.\n",
8989
"u[.5/dx : 1/dx+1]=2 #then set u = 2 between 0.5 and 1 as per our I.C.s\n",
9090
"\n",
91-
"un = np.ones(nx) #initialize our placeholder array un, to hold the time-stepped solution"
91+
"un = numpy.ones(nx) #initialize our placeholder array un, to hold the time-stepped solution"
9292
],
9393
"language": "python",
9494
"metadata": {},
@@ -116,7 +116,7 @@
116116
" ###u[i] = un[i]-c*dt/dx*(un[i]-un[i-1]) \n",
117117
"\n",
118118
" \n",
119-
"plt.plot(np.linspace(0,2,nx),u) ##Plot the results"
119+
"pyplot.plot(numpy.linspace(0,2,nx),u) ##Plot the results"
120120
],
121121
"language": "python",
122122
"metadata": {},

lessons/03_CFL_Condition.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
"cell_type": "code",
6161
"collapsed": false,
6262
"input": [
63-
"import numpy as np #numpy is a library for array operations akin to MATLAB\n",
64-
"import matplotlib.pyplot as plt #matplotlib is 2D plotting library\n",
63+
"import numpy #numpy is a library for array operations akin to MATLAB\n",
64+
"from matplotlib import pyplot #matplotlib is 2D plotting library\n",
6565
"%matplotlib inline\n",
6666
"\n",
6767
"def linearconv(nx):\n",
@@ -70,17 +70,17 @@
7070
" dt = .025 #dt is the amount of time each timestep covers (delta t)\n",
7171
" c = 1\n",
7272
"\n",
73-
" u = np.ones(nx) #defining a numpy array which is nx elements long with every value equal to 1.\n",
73+
" u = numpy.ones(nx) #defining a numpy array which is nx elements long with every value equal to 1.\n",
7474
" u[.5/dx : 1/dx+1]=2 #setting u = 2 between 0.5 and 1 as per our I.C.s\n",
7575
"\n",
76-
" un = np.ones(nx) #initializing our placeholder array, un, to hold the values we calculate for the n+1 timestep\n",
76+
" un = numpy.ones(nx) #initializing our placeholder array, un, to hold the values we calculate for the n+1 timestep\n",
7777
"\n",
7878
" for n in range(nt): #iterate through time\n",
7979
" un = u.copy() ##copy the existing values of u into un\n",
8080
" for i in range(1,nx):\n",
8181
" u[i] = un[i]-c*dt/dx*(un[i]-un[i-1])\n",
8282
" \n",
83-
" plt.plot(np.linspace(0,2,nx),u);\n",
83+
" pyplot.plot(numpy.linspace(0,2,nx),u);\n",
8484
" "
8585
],
8686
"language": "python",
@@ -237,8 +237,8 @@
237237
"cell_type": "code",
238238
"collapsed": false,
239239
"input": [
240-
"import numpy as np\n",
241-
"import matplotlib.pyplot as plt\n",
240+
"import numpy\n",
241+
"from matplotlib import pyplot\n",
242242
"\n",
243243
"def linearconv(nx):\n",
244244
" dx = 2./(nx-1)\n",
@@ -248,17 +248,17 @@
248248
" \n",
249249
" dt = sigma*dx\n",
250250
"\n",
251-
" u = np.ones(nx) \n",
251+
" u = numpy.ones(nx) \n",
252252
" u[.5/dx : 1/dx+1]=2\n",
253253
"\n",
254-
" un = np.ones(nx)\n",
254+
" un = numpy.ones(nx)\n",
255255
"\n",
256256
" for n in range(nt): #iterate through time\n",
257257
" un = u.copy() ##copy the existing values of u into un\n",
258258
" for i in range(1,nx):\n",
259259
" u[i] = un[i]-c*dt/dx*(un[i]-un[i-1])\n",
260260
" \n",
261-
" plt.plot(np.linspace(0,2,nx),u)"
261+
" pyplot.plot(numpy.linspace(0,2,nx),u)"
262262
],
263263
"language": "python",
264264
"metadata": {},

lessons/04_Step_3.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
117117
"cell_type": "code",
118118
"collapsed": false,
119119
"input": [
120-
"import numpy as np #loading our favorite library\n",
121-
"import matplotlib.pyplot as plt #and the useful plotting library\n",
120+
"import numpy #loading our favorite library\n",
121+
"from matplotlib import pyplot #and the useful plotting library\n",
122122
"%matplotlib inline\n",
123123
"\n",
124124
"nx = 41\n",
@@ -129,17 +129,17 @@
129129
"dt = sigma*dx**2/nu #dt is defined using sigma ... more later!\n",
130130
"\n",
131131
"\n",
132-
"u = np.ones(nx) #a numpy array with nx elements all equal to 1.\n",
132+
"u = numpy.ones(nx) #a numpy array with nx elements all equal to 1.\n",
133133
"u[.5/dx : 1/dx+1]=2 #setting u = 2 between 0.5 and 1 as per our I.C.s\n",
134134
"\n",
135-
"un = np.ones(nx) #our placeholder array, un, to advance the solution in time\n",
135+
"un = numpy.ones(nx) #our placeholder array, un, to advance the solution in time\n",
136136
"\n",
137137
"for n in range(nt): #iterate through time\n",
138138
" un = u.copy() ##copy the existing values of u into un\n",
139139
" for i in range(1,nx-1):\n",
140140
" u[i] = un[i] + nu*dt/dx**2*(un[i+1]-2*un[i]+un[i-1])\n",
141141
" \n",
142-
"plt.plot(np.linspace(0,2,nx), u);"
142+
"pyplot.plot(numpy.linspace(0,2,nx), u);"
143143
],
144144
"language": "python",
145145
"metadata": {},

lessons/05_Step_4.ipynb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"cell_type": "code",
116116
"collapsed": false,
117117
"input": [
118-
"import numpy as np\n",
118+
"import numpy\n",
119119
"import sympy"
120120
],
121121
"language": "python",
@@ -154,7 +154,7 @@
154154
"collapsed": false,
155155
"input": [
156156
"x, nu, t = sympy.symbols('x nu t')\n",
157-
"phi = sympy.exp(-(x-4*t)**2/(4*nu*(t+1))) + sympy.exp(-(x-4*t-2*np.pi)**2/(4*nu*(t+1)))\n",
157+
"phi = sympy.exp(-(x-4*t)**2/(4*nu*(t+1))) + sympy.exp(-(x-4*t-2*numpy.pi)**2/(4*nu*(t+1)))\n",
158158
"phi"
159159
],
160160
"language": "python",
@@ -325,22 +325,22 @@
325325
"cell_type": "code",
326326
"collapsed": false,
327327
"input": [
328-
"import matplotlib.pyplot as plt\n",
328+
"from matplotlib import pyplot\n",
329329
"%matplotlib inline\n",
330330
"\n",
331331
"###variable declarations\n",
332332
"nx = 101\n",
333333
"nt = 100\n",
334-
"dx = 2*np.pi/(nx-1)\n",
334+
"dx = 2*numpy.pi/(nx-1)\n",
335335
"nu = .07\n",
336336
"dt = dx*nu\n",
337337
"\n",
338-
"x = np.linspace(0, 2*np.pi, nx)\n",
339-
"#u = np.empty(nx)\n",
340-
"un = np.empty(nx)\n",
338+
"x = numpy.linspace(0, 2*np.pi, nx)\n",
339+
"#u = numpy.empty(nx)\n",
340+
"un = numpy.empty(nx)\n",
341341
"t = 0\n",
342342
"\n",
343-
"u = np.asarray([ufunc(t, x0, nu) for x0 in x])\n",
343+
"u = numpy.asarray([ufunc(t, x0, nu) for x0 in x])\n",
344344
"u"
345345
],
346346
"language": "python",
@@ -380,10 +380,10 @@
380380
"cell_type": "code",
381381
"collapsed": false,
382382
"input": [
383-
"plt.figure(figsize=(11,7), dpi=100)\n",
384-
"plt.plot(x,u, marker='o', lw=2)\n",
385-
"plt.xlim([0,2*np.pi])\n",
386-
"plt.ylim([0,10]);"
383+
"pyplot.figure(figsize=(11,7), dpi=100)\n",
384+
"pyplot.plot(x,u, marker='o', lw=2)\n",
385+
"pyplot.xlim([0,2*numpy.pi])\n",
386+
"pyplot.ylim([0,10]);"
387387
],
388388
"language": "python",
389389
"metadata": {},
@@ -438,7 +438,7 @@
438438
" u[-1] = un[-1] - un[-1] * dt/dx * (un[-1] - un[-2]) + nu*dt/dx**2*\\\n",
439439
" (un[0]-2*un[-1]+un[-2])\n",
440440
" \n",
441-
"u_analytical = np.asarray([ufunc(nt*dt, xi, nu) for xi in x])"
441+
"u_analytical = numpy.asarray([ufunc(nt*dt, xi, nu) for xi in x])"
442442
],
443443
"language": "python",
444444
"metadata": {},
@@ -449,12 +449,12 @@
449449
"cell_type": "code",
450450
"collapsed": false,
451451
"input": [
452-
"plt.figure(figsize=(11,7), dpi=100)\n",
453-
"plt.plot(x,u, marker='o', lw=2, label='Computational')\n",
454-
"plt.plot(x, u_analytical, label='Analytical')\n",
455-
"plt.xlim([0,2*np.pi])\n",
456-
"plt.ylim([0,10])\n",
457-
"plt.legend();"
452+
"pyplot.figure(figsize=(11,7), dpi=100)\n",
453+
"pyplot.plot(x,u, marker='o', lw=2, label='Computational')\n",
454+
"pyplot.plot(x, u_analytical, label='Analytical')\n",
455+
"pyplot.xlim([0,2*numpy.pi])\n",
456+
"pyplot.ylim([0,10])\n",
457+
"pyplot.legend();"
458458
],
459459
"language": "python",
460460
"metadata": {},

lessons/06_Array_Operations_with_NumPy.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"cell_type": "code",
5757
"collapsed": false,
5858
"input": [
59-
"import numpy as np"
59+
"import numpy"
6060
],
6161
"language": "python",
6262
"metadata": {},
@@ -67,7 +67,7 @@
6767
"cell_type": "code",
6868
"collapsed": false,
6969
"input": [
70-
"u = np.array((0, 1, 2, 3, 4, 5))\n",
70+
"u = numpy.array((0, 1, 2, 3, 4, 5))\n",
7171
"\n",
7272
"for i in range(1,len(u)):\n",
7373
" print u[i]-u[i-1]"
@@ -140,11 +140,11 @@
140140
"sigma = .2\n",
141141
"dt = sigma*dx\n",
142142
"\n",
143-
"x = np.linspace(0,2,nx)\n",
144-
"y = np.linspace(0,2,ny)\n",
143+
"x = numpy.linspace(0,2,nx)\n",
144+
"y = numpy.linspace(0,2,ny)\n",
145145
"\n",
146-
"u = np.ones((ny,nx)) ##create a 1xn vector of 1's\n",
147-
"un = np.ones((ny,nx)) ##\n",
146+
"u = numpy.ones((ny,nx)) ##create a 1xn vector of 1's\n",
147+
"un = numpy.ones((ny,nx)) ##\n",
148148
"\n",
149149
"###Assign initial conditions\n",
150150
"\n",
@@ -169,7 +169,7 @@
169169
"collapsed": false,
170170
"input": [
171171
"%%timeit\n",
172-
"u = np.ones((ny,nx))\n",
172+
"u = numpy.ones((ny,nx))\n",
173173
"u[.5/dy:1/dy+1,.5/dx:1/dx+1]=2\n",
174174
"\n",
175175
"for n in range(nt+1): ##loop across number of time steps\n",
@@ -208,7 +208,7 @@
208208
"collapsed": false,
209209
"input": [
210210
"%%timeit\n",
211-
"u = np.ones((ny,nx))\n",
211+
"u = numpy.ones((ny,nx))\n",
212212
"u[.5/dy:1/dy+1,.5/dx:1/dx+1]=2\n",
213213
"\n",
214214
"for n in range(nt+1): ##loop across number of time steps\n",

0 commit comments

Comments
 (0)