[SciPy-User] scipy.sparse.linalg.cg statistics?

Nico Schlömer nico.schloemer@gmail....
Sat Oct 2 05:19:56 CDT 2010


Good idea, thanks for the hint!

On Fri, Oct 1, 2010 at 2:56 PM, Pauli Virtanen <pav@iki.fi> wrote:
> Fri, 01 Oct 2010 12:06:30 +0200, Nico Schlömer wrote:
>>> Use the 'callback' argument.
>>
>> That works alright I guess.
>> What I do right now is creating a *global array that's filled up as the
>> callback function is called, after which I go ahead and plot it. Using a
>> global variable here seems somewhat ugly to me -- might there be a more
>> elegant solution at all?
>
> Use variables from the outer scope:
>
> def doit(M, b):
>    residuals = []
>
>    def callback(xk):
>        residuals.append(M*xk - b)
>
>    sol, info = scipy.sparse.linalg.cg(M, b, callback=callback)
>    return residuals
>
>
> http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces
>
> http://www.saltycrane.com/blog/2008/01/python-variable-scope-notes/
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list