You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: ch02data/068QuakesSolution.ipynb.py
+24-13
Original file line number
Diff line number
Diff line change
@@ -170,7 +170,7 @@
170
170
# As a first approach, we will set the first eartquake to be the largest and as we iterate over the others we will replace the first one with whatever is larger.
171
171
172
172
# %%
173
-
quakes=requests_json['features']
173
+
quakes=quakes_json['features']
174
174
175
175
largest_so_far=quakes[0]
176
176
forquakeinquakes:
@@ -212,26 +212,38 @@
212
212
# We saw something similar in the [Greengraph example](../ch01python/010exemplar.html#More-complex-functions) [(notebook version)](../ch01python/010exemplar.ipynb#More-complex-functions) of the previous chapter.
213
213
214
214
# %%
215
-
defrequest_map_at(lat, long, satellite=True,
216
-
zoom=10, size=(400, 400)):
217
-
base="https://static-maps.yandex.ru/1.x/?"
215
+
defdeg2num(lat_deg, lon_deg, zoom):
216
+
"""Convert latitude and longitude to XY tiles coordinates."""
# As a test we can check the map displayed for the coordinates of the [Prime meridian at the Royal Observatory Greenwich](https://geohack.toolforge.org/geohack.php?pagename=Prime_meridian_(Greenwich)¶ms=51_28_40.1_N_0_0_5.3_W_type:landmark_globe:earth_region:GB_scale:1000)
Copy file name to clipboardexpand all lines: ch02data/082NumPy.ipynb.py
+47
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,15 @@
30
30
# * [NumPy](https://numpy.org/), a fast numeric computing library offering a flexible *n*-dimensional array type.
31
31
# * [IPython](https://ipython.readthedocs.io/en/stable/overview.html), an interactive Python interpreter that later led to the [Jupyter notebook](https://jupyter.org/) interface.
32
32
#
33
+
# <details><summary>Who created those?</summary>
34
+
#
35
+
# * [John D. Hunter](https://en.wikipedia.org/wiki/John_D._Hunter) created Matplotlib
36
+
# * [Travis Oliphant](https://en.wikipedia.org/wiki/Travis_Oliphant) is the primary creator of NumPy, founding contributor of SciPy, and he's also the founder of Anaconda
37
+
# * [Fernando Perez](https://en.wikipedia.org/wiki/Fernando_P%C3%A9rez_\(software_developer\)) created IPython
38
+
#
39
+
# </details>
40
+
#
41
+
#
33
42
# By combining a plotting library, a fast numeric library, and an easy-to-use interface allowing live plotting commands in a persistent environment, the powerful capabilities of MATLAB were matched by a free and open toolchain.
34
43
#
35
44
# We've learned about Matplotlib and IPython in this course already. NumPy is the last part of the trilogy.
@@ -533,6 +542,44 @@
533
542
# %%
534
543
v @ v
535
544
545
+
# %% [markdown]
546
+
# We can alternatively use a built in function:
547
+
548
+
# %%
549
+
np.dot(a, b)
550
+
551
+
# %% [markdown]
552
+
# Though it is possible to represent this in the algebra of broadcasting and newaxis:
553
+
554
+
# %%
555
+
a[:, :, np.newaxis].shape
556
+
557
+
# %%
558
+
b[np.newaxis, :, :].shape
559
+
560
+
# %%
561
+
a[:, :, np.newaxis] *b[np.newaxis, :, :]
562
+
563
+
# %%
564
+
(a[:, :, np.newaxis] *b[np.newaxis, :, :]).sum(1)
565
+
566
+
# %% [markdown]
567
+
# Or if you prefer:
568
+
569
+
# %%
570
+
(a.reshape(3, 3, 1) *b.reshape(1, 3, 3)).sum(1)
571
+
572
+
# %% [markdown]
573
+
# We use broadcasting to generate $A_{ij}B_{jk}$ as a 3-d matrix:
574
+
575
+
# %%
576
+
a.reshape(3, 3, 1) *b.reshape(1, 3, 3)
577
+
578
+
# %% [markdown]
579
+
# Then we sum over the middle, $j$ axis, [which is the 1-axis of three axes numbered (0,1,2)] of this 3-d matrix. Thus we generate $\Sigma_j A_{ij}B_{jk}$.
580
+
#
581
+
# We can see that the broadcasting concept gives us a powerful and efficient way to express many linear algebra operations computationally.
0 commit comments