arraysfor-loopnumpynotation

Is there clean mathematical notation of a for-loop?


I'm looking for a way to describe the mathematical background of my code. Using numpy I sum two higher-dimensional arrays:

a.shape  # (10, 5, 2)
b.shape  # (5, 2)
c = a + b
c.shape  # (10, 5, 2)

Is there a pure mathematical notation for this (so WITHOUT introducing for-loops or numpy conventions in my text)? What I'm trying to avoid is to have to write something like this:

c_{1, y, z} = a_{1, y, z} + b_{y, z}
c_{2, y, z} = a_{2, y, z} + b_{y, z}
...
c_{10, y, z} = a_{10, y, z} + b_{y, z}

Edit: I'm using LaTeX for the documentation, so indexing is no problem. I'm currently using more or less the suggestion from Tobias. I was just hoping that there may be some other solution I haven't thought of.


Solution

  • Just write

    Image of equation for Image of range.

    In LaTeX:

    $C_{i,y,z} = a_{i,y,z} + b_{y,z}$ for $i = 1, \ldots, 10$
    

    Rendered as HTML:

    Ci,y,z = ai,y,z + by,z for i = 1, …, 10

    You find this form often in books on numerics like Numerical Recipes (e.g., page 57).

    If you have larger sections of code, an alternative is to use pseudo-code.