Understanding Python Code
subhabangalore at gmail.com
subhabangalore at gmail.com
Thu Jun 19 01:50:52 EDT 2014
On Thursday, June 19, 2014 12:45:49 AM UTC+5:30, Ian wrote:
>
>
> > The questions are,
>
> > i) prev_f_sum = sum(f_prev[k]*a[k][st] for k in states)
>
> > here f_prev is called,
>
> > f_prev is assigned to f_curr ["f_prev = f_curr"]
>
> > f_curr[st] is again being calculated as, ["f_curr[st] = e[st][x_i] * prev_f_sum"] which again calls "prev_f_sum"
>
> >
>
> > I am slightly confused which one would be first calculated and how to proceed next?
>
>
>
> These things that you describe as "calls" are not calls. f_prev and
>
> f_curr are data structures (in this case dicts), not functions.
>
> Accessing "f_prev[k]" does not call f_prev or in any way cause
>
> f_prev[k] to be computed; it just looks up what value is recorded in
>
> the f_prev dict for the key k.
>
>
>
> Python is an imperative language, not declarative. If you want to
>
> know what order these things are calculated in, just follow the
>
> program flow.
Thank you for the reply. But as I checked it again I found,
f_prev[k] is giving values of f_curr[st] = e[st][x_i] * prev_f_sum
which is calculated later and again uses prev_f_sum.
Regards,
Subhabrata Banerjee.
More information about the Python-list
mailing list