Skip to content

Commit

Permalink
Fix syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Jun 16, 2023
1 parent 1291a5c commit 799c94a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions advanced/apply_ufunc/complex-output-numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"This function expects a 1D array as input, and returns a 1D array as output.\n",
"\n",
"\n",
"```{tip}Exercise\n",
"```{tip} Exercise\n",
"How many core dimensions does `numpy.interp` handle?\n",
"```\n",
"```{tip}Solution\n",
"```{tip} Solution\n",
":class:dropdown\n",
"\n",
"One.\n",
Expand Down Expand Up @@ -125,16 +125,15 @@
"user_expressions": []
},
"source": [
"```{tip}Exercise\n",
"\n",
"```{tip} Exercise\n",
"\n",
"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`\n",
"\n",
"```python\n",
"def add_new_dim(array):\n",
" return np.expand_dims(array, axis=0)\n",
"```\n",
"```{tip}Solution\n",
"```{tip} Solution\n",
":class: dropdown\n",
"\n",
"```{code-cell} python\n",
Expand Down Expand Up @@ -320,7 +319,7 @@
"user_expressions": []
},
"source": [
"```{tip}Exercise\n",
"```{tip} Exercise\n",
"\n",
"We presented the concept of \"core dimensions\" as the \"smallest unit of data the function could handle.\" Do you understand how the following use of `apply_ufunc` generalizes to an array with more than one dimension? Try it with `air3d = xr.tutorial.load_dataset(\"air_temperature\").air.isel(time=0)`\n",
"\n",
Expand All @@ -333,7 +332,7 @@
")\n",
"```\n",
"\n",
"```{tip}Solution\n",
"```{tip} Solution\n",
":class:dropdown\n",
"\n",
"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=[[], []]`\n",
Expand Down

0 comments on commit 799c94a

Please sign in to comment.