Skip to content

Commit 7d70d22

Browse files
committed
adding np.ix_
1 parent 11e2aa4 commit 7d70d22

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

intermediate/indexing/advanced-indexing.ipynb

+20-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@
110110
"- *Orthogonal* or *outer* indexing allows for indexing along each dimension independently, treating the indexers as one-dimensional arrays. The principle of outer or orthogonal indexing is that the result mirrors the effect of independently indexing along each dimension with integer or boolean arrays, treating both the indexed and indexing arrays as one-dimensional. This method of indexing is analogous to vector indexing in programming languages like MATLAB, Fortran, and R, where each indexer component independently selects along its corresponding dimension. This is the default behavior in Xarray.\n",
111111
"\n",
112112
"\n",
113+
":::\n",
114+
"\n",
115+
":::{note} Orthogonal indexing with NumPy\n",
116+
":class: dropdown\n",
117+
"\n",
118+
"While Pointwise indexing is the default behavior in NumPy, you can achieve orthogonal indexing by using the [`np.ix_` function](https://numpy.org/doc/stable/reference/generated/numpy.ix_.html). This function constructs an open mesh from multiple arrays, allowing you to index along each dimension independently similar to Xarray indexig behavior. For example: \n",
119+
"\n",
120+
"```python\n",
121+
"ixgrid = np.ix_([0, 2, 4], [0, 2, 4])\n",
122+
"np_array[ixgrid]\n",
123+
"```\n",
124+
"\n",
113125
":::"
114126
]
115127
},
@@ -138,6 +150,7 @@
138150
"\n",
139151
"xr.set_options(display_expand_attrs=False)\n",
140152
"np.set_printoptions(threshold=10, edgeitems=2)\n",
153+
"%config InlineBackend.figure_format='retina'\n",
141154
"\n",
142155
"ds = xr.tutorial.load_dataset(\"air_temperature\")\n",
143156
"da_air = ds.air\n",
@@ -387,6 +400,11 @@
387400
}
388401
],
389402
"metadata": {
403+
"kernelspec": {
404+
"display_name": "Python 3 (ipykernel)",
405+
"language": "python",
406+
"name": "python3"
407+
},
390408
"language_info": {
391409
"codemirror_mode": {
392410
"name": "ipython",
@@ -396,7 +414,8 @@
396414
"mimetype": "text/x-python",
397415
"name": "python",
398416
"nbconvert_exporter": "python",
399-
"pygments_lexer": "ipython3"
417+
"pygments_lexer": "ipython3",
418+
"version": "3.12.3"
400419
},
401420
"toc": {
402421
"base_numbering": 1,

0 commit comments

Comments
 (0)