From 9cfa1b31fb7507e6ac4142e8cb0969c0a061b621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 27 Jan 2023 13:14:02 +0100 Subject: [PATCH] NumPy indexing --- README.md | 10 ++++++---- index.html | 18 +++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7406ec8..dc309c1 100644 --- a/README.md +++ b/README.md @@ -2661,23 +2661,25 @@ import numpy as np * **Passing a tuple of axes will chain the operations like this: `'.(axis_1).(axis_2 - 1 if axis_2 > axis_1 else axis_2)'`.** ### Indexing -**All examples also allow assignments.** ```bash = <2d_array>[row_index, column_index] # <3d_a>[table_i, row_i, column_i] <1d_view> = <2d_array>[row_index] # <3d_a>[table_i, row_i] <1d_view> = <2d_array>[:, column_index] # <3d_a>[table_i, :, column_i] +<2d_view> = <2d_array>[row_range, column_range] # <3d_a>[table_i, row_r, column_r] ``` ```bash -<1d_array> = <2d_array>[row_indexes, column_indexes] # <3d_a>[table_is, row_is, column_is] -<2d_array> = <2d_array>[row_indexes] # <3d_a>[table_is, row_is] -<2d_array> = <2d_array>[:, column_indexes] # <3d_a>[table_is, :, column_is] +<2d_array> = <2d_array>[row_indexes] # <3d_a>[table_i/s, row_is] +<2d_array> = <2d_array>[:, column_indexes] # <3d_a>[table_i/s, :, column_is] +<1d_array> = <2d_array>[row_indexes, column_indexes] # <3d_a>[table_i/s, row_is, column_is] +<1d_array> = <2d_array>[row_indexes, column_index] # <3d_a>[table_i/s, row_is, column_i] ``` ```bash <2d_bools> = <2d_array> ><== # 1d_array must have size of a row. <1d/2d_a> = <2d_array>[<2d/1d_bools>] # 1d_bools must have size of a column. ``` +* **Indexes should not be tuples because Python converts `'obj[i, j]'` to `'obj[(i, j)]'`.** ### Broadcasting **Broadcasting is a set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.** diff --git a/index.html b/index.html index b09dc7f..c6b0514 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -2178,19 +2178,23 @@ drawer = cg.output.GraphvizOutput(output_file=filename)
  • Axis is an index of the dimension that gets aggregated. Leftmost dimension has index 0. Summing the RGB image along axis 2 will return a greyscale image with shape (50, 100).
  • Passing a tuple of axes will chain the operations like this: '<array>.<method>(axis_1).<method>(axis_2 - 1 if axis_2 > axis_1 else axis_2)'.
  • -

    Indexing

    All examples also allow assignments.

    <el>       = <2d_array>[row_index, column_index]        # <3d_a>[table_i, row_i, column_i]
    +

    Indexing

    <el>       = <2d_array>[row_index, column_index]        # <3d_a>[table_i, row_i, column_i]
     <1d_view>  = <2d_array>[row_index]                      # <3d_a>[table_i, row_i]
     <1d_view>  = <2d_array>[:, column_index]                # <3d_a>[table_i, :, column_i]
    +<2d_view>  = <2d_array>[row_range, column_range]        # <3d_a>[table_i, row_r, column_r]
     
    - -
    <1d_array> = <2d_array>[row_indexes, column_indexes]    # <3d_a>[table_is, row_is, column_is]
    -<2d_array> = <2d_array>[row_indexes]                    # <3d_a>[table_is, row_is]
    -<2d_array> = <2d_array>[:, column_indexes]              # <3d_a>[table_is, :, column_is]
    +
    <2d_array> = <2d_array>[row_indexes]                    # <3d_a>[table_i/s, row_is]
    +<2d_array> = <2d_array>[:, column_indexes]              # <3d_a>[table_i/s, :, column_is]
    +<1d_array> = <2d_array>[row_indexes, column_indexes]    # <3d_a>[table_i/s, row_is, column_is]
    +<1d_array> = <2d_array>[row_indexes, column_index]      # <3d_a>[table_i/s, row_is, column_i]
     
    <2d_bools> = <2d_array> ><== <el/1d/2d_array>           # 1d_array must have size of a row.
     <1d/2d_a>  = <2d_array>[<2d/1d_bools>]                  # 1d_bools must have size of a column.
     
    +
      +
    • Indexes should not be tuples because Python converts 'obj[i, j]' to 'obj[(i, j)]'.
    • +

    Broadcasting

    Broadcasting is a set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.

    left  = [[0.1], [0.6], [0.8]]                           # Shape: (3, 1)
     right = [ 0.1 ,  0.6 ,  0.8 ]                           # Shape: (3,)
     
    @@ -2919,7 +2923,7 @@ $ pyinstaller script.py --add-data '<path>:.'