|
138 | 138 | "tags": []
|
139 | 139 | },
|
140 | 140 | "source": [
|
141 |
| - "```{exercise}\n", |
142 |
| - ":label: newdim\n", |
| 141 | + "::::{admonition} Exercise\n", |
| 142 | + ":class: tip\n", |
143 | 143 | "\n",
|
144 | 144 | "Apply the following function using `apply_ufunc`. It adds a new dimension to the input array, let's call it `newdim`. Specify the new dimension using `output_core_dims`. Do you need any `input_core_dims`?\n",
|
145 | 145 | "\n",
|
146 | 146 | "```python\n",
|
147 | 147 | "def add_new_dim(array):\n",
|
148 | 148 | " return np.expand_dims(array, axis=-1)\n",
|
149 | 149 | "```\n",
|
150 |
| - "````{solution} newdim\n", |
| 150 | + "\n", |
| 151 | + ":::{admonition} Solution\n", |
151 | 152 | ":class: dropdown\n",
|
152 | 153 | "\n",
|
153 |
| - "``` python\n", |
| 154 | + "```python\n", |
154 | 155 | "def add_new_dim(array):\n",
|
155 | 156 | " return np.expand_dims(array, axis=-1)\n",
|
156 | 157 | "\n",
|
|
161 | 162 | " output_core_dims=[[\"newdim\"]],\n",
|
162 | 163 | ")\n",
|
163 | 164 | "```\n",
|
164 |
| - "````" |
| 165 | + ":::\n", |
| 166 | + "::::" |
165 | 167 | ]
|
166 | 168 | },
|
167 | 169 | {
|
|
327 | 329 | "tags": []
|
328 | 330 | },
|
329 | 331 | "source": [
|
330 |
| - "````{exercise}\n", |
331 |
| - ":label: generalize\n", |
| 332 | + "::::{admonition} Exercise\n", |
| 333 | + ":class: tip\n", |
332 | 334 | "\n",
|
333 | 335 | "We presented the concept of \"core dimensions\" as the \"smallest unit of data the function could handle.\" Do you understand how the above use of `apply_ufunc` generalizes to an array with more than one dimension? \n",
|
334 | 336 | "\n",
|
|
337 | 339 | "air3d = xr.tutorial.load_dataset(\"air_temperature\").air)\n",
|
338 | 340 | "``` \n",
|
339 | 341 | "Your goal is to have a minimum and maximum value of temperature across all latitudes for a given time and longitude.\n",
|
340 |
| - "````\n", |
341 | 342 | "\n",
|
342 |
| - "````{solution} generalize\n", |
| 343 | + ":::{admonition} Solution\n", |
343 | 344 | ":class: dropdown\n",
|
344 | 345 | "\n",
|
345 | 346 | "We want to use `minmax` to compute the minimum and maximum along the \"lat\" dimension always, regardless of how many dimensions are on the input. So we specify `input_core_dims=[[\"lat\"]]`. The output does not contain the \"lat\" dimension, but we expect two returned variables. So we pass an empty list `[]` for each returned array, so `output_core_dims=[[], []]` just as before.\n",
|
|
352 | 353 | " input_core_dims=[[\"lat\"]],\n",
|
353 | 354 | " output_core_dims=[[],[]],\n",
|
354 | 355 | ")\n",
|
355 |
| - "```\n", |
356 |
| - "````" |
| 356 | + ":::\n", |
| 357 | + "::::" |
357 | 358 | ]
|
358 | 359 | }
|
359 | 360 | ],
|
|
0 commit comments