|
17 | 17 | "source": [
|
18 | 18 | "## Overview\n",
|
19 | 19 | "\n",
|
20 |
| - "In the previous notebooks, we learned basic forms of indexing with Xarray (positional and name based dimensions, integer and label based indexing), datetime Indexing, and nearest neighbor lookups. Xarray positional indexing deviates from the NumPy when indexing with multiple arrays like `arr[[0, 1], [0, 1]]`. In this tutorial we learn about this difference and how to do vectorized/pointwise indexing using Xarray.\n", |
| 20 | + "In the previous notebooks, we learned basic forms of indexing with Xarray (positional and name based dimensions, integer and label based indexing), datetime Indexing, and nearest neighbor lookups. Xarray positional indexing deviates from the NumPy when indexing with multiple arrays like `arr[[0, 1], [0, 1]]`.\n", |
| 21 | + "\n", |
| 22 | + "In this tutorial we learn about this difference and how to do vectorized/pointwise indexing using Xarray.\n", |
21 | 23 | "\n",
|
22 | 24 | "For this notebook, first, we should learn about orthogonal (i.e. outer) and vectorized (i.e. pointwise) indexing concepts. \n",
|
23 | 25 | "\n",
|
|
31 | 33 | },
|
32 | 34 | {
|
33 | 35 | "cell_type": "code",
|
34 |
| - "execution_count": 42, |
| 36 | + "execution_count": 47, |
35 | 37 | "metadata": {},
|
36 | 38 | "outputs": [
|
37 | 39 | {
|
|
44 | 46 | " [21, 22, ..., 24, 25]])"
|
45 | 47 | ]
|
46 | 48 | },
|
47 |
| - "execution_count": 42, |
| 49 | + "execution_count": 47, |
48 | 50 | "metadata": {},
|
49 | 51 | "output_type": "execute_result"
|
50 | 52 | }
|
|
66 | 68 | },
|
67 | 69 | {
|
68 | 70 | "cell_type": "code",
|
69 |
| - "execution_count": 43, |
| 71 | + "execution_count": 48, |
70 | 72 | "metadata": {},
|
71 | 73 | "outputs": [
|
72 | 74 | {
|
|
441 | 443 | " ...,\n",
|
442 | 444 | " [16, 17, ..., 19, 20],\n",
|
443 | 445 | " [21, 22, ..., 24, 25]])\n",
|
444 |
| - "Dimensions without coordinates: dim_0, dim_1</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'></div><ul class='xr-dim-list'><li><span>dim_0</span>: 5</li><li><span>dim_1</span>: 5</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-99ce812d-8ac9-4e4f-a34c-72175a80a4d1' class='xr-array-in' type='checkbox' checked><label for='section-99ce812d-8ac9-4e4f-a34c-72175a80a4d1' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25</span></div><div class='xr-array-data'><pre>array([[ 1, 2, ..., 4, 5],\n", |
| 446 | + "Dimensions without coordinates: dim_0, dim_1</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'></div><ul class='xr-dim-list'><li><span>dim_0</span>: 5</li><li><span>dim_1</span>: 5</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-d70dbedf-cbdc-49d1-bf71-061abecd150a' class='xr-array-in' type='checkbox' checked><label for='section-d70dbedf-cbdc-49d1-bf71-061abecd150a' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25</span></div><div class='xr-array-data'><pre>array([[ 1, 2, ..., 4, 5],\n", |
445 | 447 | " [ 6, 7, ..., 9, 10],\n",
|
446 | 448 | " ...,\n",
|
447 | 449 | " [16, 17, ..., 19, 20],\n",
|
448 |
| - " [21, 22, ..., 24, 25]])</pre></div></div></li><li class='xr-section-item'><input id='section-7aabddcb-df05-4363-be31-836d8138e41e' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-7aabddcb-df05-4363-be31-836d8138e41e' class='xr-section-summary' title='Expand/collapse section'>Coordinates: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-29a47bfe-a5f5-4897-b22d-649160fef139' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-29a47bfe-a5f5-4897-b22d-649160fef139' class='xr-section-summary' title='Expand/collapse section'>Indexes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-e8d8f9fe-bc35-46c5-96dd-8ffbeadb8084' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-e8d8f9fe-bc35-46c5-96dd-8ffbeadb8084' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" |
| 450 | + " [21, 22, ..., 24, 25]])</pre></div></div></li><li class='xr-section-item'><input id='section-0f5204e1-b4e9-4a04-bde3-a957f811243b' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-0f5204e1-b4e9-4a04-bde3-a957f811243b' class='xr-section-summary' title='Expand/collapse section'>Coordinates: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-6b04e499-d4ae-4cfc-b8b6-2afe2ba7f64e' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-6b04e499-d4ae-4cfc-b8b6-2afe2ba7f64e' class='xr-section-summary' title='Expand/collapse section'>Indexes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-b69aa3d6-758a-431c-8a51-2a7faf8398fc' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-b69aa3d6-758a-431c-8a51-2a7faf8398fc' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" |
449 | 451 | ],
|
450 | 452 | "text/plain": [
|
451 | 453 | "<xarray.DataArray (dim_0: 5, dim_1: 5)>\n",
|
|
457 | 459 | "Dimensions without coordinates: dim_0, dim_1"
|
458 | 460 | ]
|
459 | 461 | },
|
460 |
| - "execution_count": 43, |
| 462 | + "execution_count": 48, |
461 | 463 | "metadata": {},
|
462 | 464 | "output_type": "execute_result"
|
463 | 465 | }
|
|
470 | 472 | },
|
471 | 473 | {
|
472 | 474 | "cell_type": "code",
|
473 |
| - "execution_count": 44, |
| 475 | + "execution_count": 49, |
474 | 476 | "metadata": {},
|
475 | 477 | "outputs": [
|
476 | 478 | {
|
|
479 | 481 | "array([ 1, 13, 25])"
|
480 | 482 | ]
|
481 | 483 | },
|
482 |
| - "execution_count": 44, |
| 484 | + "execution_count": 49, |
483 | 485 | "metadata": {},
|
484 | 486 | "output_type": "execute_result"
|
485 | 487 | }
|
|
490 | 492 | },
|
491 | 493 | {
|
492 | 494 | "cell_type": "code",
|
493 |
| - "execution_count": 45, |
| 495 | + "execution_count": 50, |
494 | 496 | "metadata": {},
|
495 | 497 | "outputs": [
|
496 | 498 | {
|
|
863 | 865 | "array([[ 1, 3, 5],\n",
|
864 | 866 | " [11, 13, 15],\n",
|
865 | 867 | " [21, 23, 25]])\n",
|
866 |
| - "Dimensions without coordinates: dim_0, dim_1</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'></div><ul class='xr-dim-list'><li><span>dim_0</span>: 3</li><li><span>dim_1</span>: 3</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-026ff380-84a8-43c1-93e2-46c7509a8ffb' class='xr-array-in' type='checkbox' checked><label for='section-026ff380-84a8-43c1-93e2-46c7509a8ffb' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>1 3 5 11 13 15 21 23 25</span></div><div class='xr-array-data'><pre>array([[ 1, 3, 5],\n", |
| 868 | + "Dimensions without coordinates: dim_0, dim_1</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'></div><ul class='xr-dim-list'><li><span>dim_0</span>: 3</li><li><span>dim_1</span>: 3</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-8fd865dc-8567-451f-b112-8c1b2498ed3c' class='xr-array-in' type='checkbox' checked><label for='section-8fd865dc-8567-451f-b112-8c1b2498ed3c' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>1 3 5 11 13 15 21 23 25</span></div><div class='xr-array-data'><pre>array([[ 1, 3, 5],\n", |
867 | 869 | " [11, 13, 15],\n",
|
868 |
| - " [21, 23, 25]])</pre></div></div></li><li class='xr-section-item'><input id='section-3c56aef8-49cc-4092-bdb0-8276ec37e94c' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-3c56aef8-49cc-4092-bdb0-8276ec37e94c' class='xr-section-summary' title='Expand/collapse section'>Coordinates: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-6949b10b-e6a2-4442-891a-4b4facda1db8' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-6949b10b-e6a2-4442-891a-4b4facda1db8' class='xr-section-summary' title='Expand/collapse section'>Indexes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-30c001f5-bed8-411f-8c59-5ccf0c56c38c' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-30c001f5-bed8-411f-8c59-5ccf0c56c38c' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" |
| 870 | + " [21, 23, 25]])</pre></div></div></li><li class='xr-section-item'><input id='section-e9e5a0e0-378a-40b8-adf8-e56945587b8e' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-e9e5a0e0-378a-40b8-adf8-e56945587b8e' class='xr-section-summary' title='Expand/collapse section'>Coordinates: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-82534dc8-bb98-4d11-8390-5523ba80f6a0' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-82534dc8-bb98-4d11-8390-5523ba80f6a0' class='xr-section-summary' title='Expand/collapse section'>Indexes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-895bd060-ffcf-4216-a98a-5eb4c446cc99' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-895bd060-ffcf-4216-a98a-5eb4c446cc99' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>" |
869 | 871 | ],
|
870 | 872 | "text/plain": [
|
871 | 873 | "<xarray.DataArray (dim_0: 3, dim_1: 3)>\n",
|
|
875 | 877 | "Dimensions without coordinates: dim_0, dim_1"
|
876 | 878 | ]
|
877 | 879 | },
|
878 |
| - "execution_count": 45, |
| 880 | + "execution_count": 50, |
879 | 881 | "metadata": {},
|
880 | 882 | "output_type": "execute_result"
|
881 | 883 | }
|
|
888 | 890 | "cell_type": "markdown",
|
889 | 891 | "metadata": {},
|
890 | 892 | "source": [
|
891 |
| - "The image below shows the difference between orthogonal and vectorized indexing for a 2D 5x5 array. \n", |
| 893 | + "The image below summarizes the difference between orthogonal and vectorized indexing for a 2D 5x5 array. \n", |
892 | 894 | "\n",
|
893 | 895 | ""
|
894 | 896 | ]
|
|
0 commit comments