Skip to content

Commit 960a5ee

Browse files
authored
Advanced Indexing - Update Exercise solution (#348)
* Advanced Indexing - Update Exercise solution The small exercise at the bottom of the page declared two DataArrays, but only used one. The solution was still correct but confusing, so I reduced the needed variable declaration to the required one and renamed. * Advanced Indexing - Update exercise Vary the showcase x and y coords as suggested by @ianhi
1 parent c178864 commit 960a5ee

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

intermediate/indexing/advanced-indexing.ipynb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,19 @@
366366
"::::{admonition} Exercise\n",
367367
":class: tip\n",
368368
"\n",
369-
"In the simple 2D 5x5 Xarray data array above, select the sub-array containing (0,0),(2,2),(4,4):\n",
369+
"In the simple 2D 5x5 Xarray data array above, select the sub-array containing (0,4),(2,2),(4,0):\n",
370370
"\n",
371371
":::{admonition} Solution\n",
372372
":class: dropdown\n",
373373
"```python\n",
374374
"\n",
375-
"indices = np.array([0, 2, 4])\n",
375+
"x_indices = np.array([0, 2, 4])\n",
376+
"y_indices = np.array([4, 2, 0])\n",
376377
"\n",
377-
"xs_da = xr.DataArray(indices, dims=\"points\")\n",
378-
"ys_da = xr.DataArray(indices, dims=\"points\")\n",
378+
"da_x = xr.DataArray(x_indices, dims=\"points\")\n",
379+
"da_y = xr.DataArray(y_indices, dims=\"points\")\n",
379380
"\n",
380-
"subset_da = da.sel(x=xs_da, y=xs_da)\n",
381+
"subset_da = da.sel(x=da_x, y=da_y)\n",
381382
"subset_da\n",
382383
"```\n",
383384
":::\n",

0 commit comments

Comments
 (0)