|
374 | 374 | "metadata": {}, |
375 | 375 | "source": [ |
376 | 376 | "<div class=\"admonition alert alert-warning\">\n", |
377 | | - " <p class=\"warning\" style=\"font-weight:bold\">Warning</p>\n", |
| 377 | + " <p class=\"admonition-title\" style=\"font-weight:bold\">Warning</p>\n", |
378 | 378 | " These arrays must be the same shape!\n", |
379 | 379 | "</div>" |
380 | 380 | ] |
|
408 | 408 | "source": [ |
409 | 409 | "### Constants\n", |
410 | 410 | "\n", |
411 | | - "NumPy proves us access to some useful constants as well - remember you should never be typing these in manually! Other libraries such as SciPy and MetPy have their own set of constants that are more domain specific." |
| 411 | + "NumPy provides us access to some useful constants as well - remember you should never be typing these in manually! Other libraries such as SciPy and MetPy have their own set of constants that are more domain specific." |
412 | 412 | ] |
413 | 413 | }, |
414 | 414 | { |
|
474 | 474 | "sin_t" |
475 | 475 | ] |
476 | 476 | }, |
| 477 | + { |
| 478 | + "cell_type": "markdown", |
| 479 | + "metadata": {}, |
| 480 | + "source": [ |
| 481 | + "and clean it up a bit by `round`ing to three decimal places." |
| 482 | + ] |
| 483 | + }, |
477 | 484 | { |
478 | 485 | "cell_type": "code", |
479 | 486 | "execution_count": null, |
|
498 | 505 | "metadata": {}, |
499 | 506 | "source": [ |
500 | 507 | "<div class=\"admonition alert alert-info\">\n", |
501 | | - " <p class=\"title\" style=\"font-weight:bold\">Info</p>\n", |
| 508 | + " <p class=\"admonition-title\" style=\"font-weight:bold\">Info</p>\n", |
502 | 509 | " Check out NumPy's list of mathematical functions <a href=https://numpy.org/doc/stable/reference/routines.math.html>here</a>!\n", |
503 | 510 | "</div>" |
504 | 511 | ] |
|
783 | 790 | "metadata": {}, |
784 | 791 | "source": [ |
785 | 792 | "<div class=\"admonition alert alert-warning\">\n", |
786 | | - " <p class=\"warning\" style=\"font-weight:bold\">Warning</p>\n", |
| 793 | + " <p class=\"admonition-title\" style=\"font-weight:bold\">Warning</p>\n", |
787 | 794 | " Slice notation is <b>exclusive</b> of the final index.\n", |
788 | 795 | "</div>" |
789 | 796 | ] |
|
792 | 799 | "cell_type": "markdown", |
793 | 800 | "metadata": {}, |
794 | 801 | "source": [ |
795 | | - "This means that slices will include ever value **up to** your `stop` index and not this index itself, like a half-open interval `[start, end)`. For example," |
| 802 | + "This means that slices will include every value **up to** your `stop` index and not this index itself, like a half-open interval `[start, end)`. For example," |
796 | 803 | ] |
797 | 804 | }, |
798 | 805 | { |
|
849 | 856 | "cell_type": "markdown", |
850 | 857 | "metadata": {}, |
851 | 858 | "source": [ |
| 859 | + "### Multidimensional slicing\n", |
852 | 860 | "This entire syntax can be extended to each dimension of multidimensional arrays." |
853 | 861 | ] |
854 | 862 | }, |
|
861 | 869 | "a" |
862 | 870 | ] |
863 | 871 | }, |
| 872 | + { |
| 873 | + "cell_type": "markdown", |
| 874 | + "metadata": {}, |
| 875 | + "source": [ |
| 876 | + "First let's pull out rows `0` through `2`, and then every `:` column for each of those" |
| 877 | + ] |
| 878 | + }, |
864 | 879 | { |
865 | 880 | "cell_type": "code", |
866 | 881 | "execution_count": null, |
|
870 | 885 | "a[0:2, :]" |
871 | 886 | ] |
872 | 887 | }, |
| 888 | + { |
| 889 | + "cell_type": "markdown", |
| 890 | + "metadata": {}, |
| 891 | + "source": [ |
| 892 | + "Similarly, let's get all rows for just column `2`," |
| 893 | + ] |
| 894 | + }, |
873 | 895 | { |
874 | 896 | "cell_type": "code", |
875 | 897 | "execution_count": null, |
|
879 | 901 | "a[:, 2]" |
880 | 902 | ] |
881 | 903 | }, |
| 904 | + { |
| 905 | + "cell_type": "markdown", |
| 906 | + "metadata": {}, |
| 907 | + "source": [ |
| 908 | + "or just take a look at the full row `:`, for every second column, `::2`," |
| 909 | + ] |
| 910 | + }, |
882 | 911 | { |
883 | 912 | "cell_type": "code", |
884 | 913 | "execution_count": null, |
|
892 | 921 | "cell_type": "markdown", |
893 | 922 | "metadata": {}, |
894 | 923 | "source": [ |
895 | | - "For any shape of array, you can use `...` to capture full slices of every un-specific dimension." |
| 924 | + "For any shape of array, you can use `...` to capture full slices of every non-specified dimension. Consider the 3-D array," |
896 | 925 | ] |
897 | 926 | }, |
898 | 927 | { |
|
914 | 943 | "c[0, ...]" |
915 | 944 | ] |
916 | 945 | }, |
| 946 | + { |
| 947 | + "cell_type": "markdown", |
| 948 | + "metadata": {}, |
| 949 | + "source": [ |
| 950 | + "and so this is equivalent to" |
| 951 | + ] |
| 952 | + }, |
| 953 | + { |
| 954 | + "cell_type": "code", |
| 955 | + "execution_count": null, |
| 956 | + "metadata": {}, |
| 957 | + "outputs": [], |
| 958 | + "source": [ |
| 959 | + "c[0, :, :]" |
| 960 | + ] |
| 961 | + }, |
| 962 | + { |
| 963 | + "cell_type": "markdown", |
| 964 | + "metadata": {}, |
| 965 | + "source": [ |
| 966 | + "for extracting every dimension across our first row. We can also flip this around," |
| 967 | + ] |
| 968 | + }, |
917 | 969 | { |
918 | 970 | "cell_type": "code", |
919 | 971 | "execution_count": null, |
|
923 | 975 | "c[..., -1]" |
924 | 976 | ] |
925 | 977 | }, |
| 978 | + { |
| 979 | + "cell_type": "markdown", |
| 980 | + "metadata": {}, |
| 981 | + "source": [ |
| 982 | + "to investigate every preceding dimension along our the last entry of our last axis, the same as `c[:, :, -1]`." |
| 983 | + ] |
| 984 | + }, |
926 | 985 | { |
927 | 986 | "cell_type": "markdown", |
928 | 987 | "metadata": {}, |
|
968 | 1027 | "nbconvert_exporter": "python", |
969 | 1028 | "pygments_lexer": "ipython3", |
970 | 1029 | "version": "3.8.10" |
971 | | - } |
| 1030 | + }, |
| 1031 | + "toc-autonumbering": false |
972 | 1032 | }, |
973 | 1033 | "nbformat": 4, |
974 | 1034 | "nbformat_minor": 4 |
|
0 commit comments