Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions intermediate/indexing/advanced-indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,19 @@
"::::{admonition} Exercise\n",
":class: tip\n",
"\n",
"In the simple 2D 5x5 Xarray data array above, select the sub-array containing (0,0),(2,2),(4,4):\n",
"In the simple 2D 5x5 Xarray data array above, select the sub-array containing (0,4),(2,2),(4,0):\n",
"\n",
":::{admonition} Solution\n",
":class: dropdown\n",
"```python\n",
"\n",
"indices = np.array([0, 2, 4])\n",
"x_indices = np.array([0, 2, 4])\n",
"y_indices = np.array([4, 2, 0])\n",
"\n",
"xs_da = xr.DataArray(indices, dims=\"points\")\n",
"ys_da = xr.DataArray(indices, dims=\"points\")\n",
"da_x = xr.DataArray(x_indices, dims=\"points\")\n",
"da_y = xr.DataArray(y_indices, dims=\"points\")\n",
"\n",
"subset_da = da.sel(x=xs_da, y=xs_da)\n",
"subset_da = da.sel(x=da_x, y=da_y)\n",
"subset_da\n",
"```\n",
":::\n",
Expand Down
Loading