干净的for循环数学符号 [英] Clean mathematical notation of a for-loop

查看:542
本文介绍了干净的for循环数学符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这确实不在这里,但我正在寻找一种描述代码数学背景的方法。我使用numpy对另外两个维数组求和:

I am sorry if this doesn't really belong here but I'm looking for a way to describe the mathematical background of my code. Using numpy I sum two more dimensional arrays:

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

是否为此使用了纯粹的数学符号(因此在我的文本中不引入for循环或numpy约定)?我要避免的是必须写这样的东西:

Is there a pure mathematical notation for this (so WITHOUT indroducing 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}

有什么想法吗?

编辑:我正在使用LaTeX作为文档,因此建立索引是没问题。我目前正在或多或少地使用Tobias的建议。我只是希望可能还有其他我没有想到的解决方案。

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.

推荐答案

只需编写

对于。

您经常在诸如数字食谱(例如,第57页)。

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.

这篇关于干净的for循环数学符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆