[SciPy-dev] openopt example mmp_1.py
Dave
dave.hirschfeld@gmail....
Sun Feb 3 11:09:48 CST 2008
Alan G Isaac <aisaac <at> american.edu> writes:
>
> In this example, how was ``ind`` created?
>
It's created with the numpy.argmax function:
In [4]: debug
> c:\python25\lib\site-packages\scikits\openopt\solvers\ukropt\nsmm.py(31)df()
30 ind = argmax(F)
---> 31 1/0
32 return p.df(x, ind)
ipdb> F.argmax()
0
ipdb> type(F.argmax())
<type 'numpy.int32'>
ipdb> id(type(F.argmax()))
1810415712
ipdb> import numpy
ipdb> id(numpy.int32)
1810415520
That's certainly not what I would expect!
A minimal test case to demonstrate this behaviour is:
>>> import numpy
>>> x = numpy.random.random(100)
>>> ind = numpy.argmax(x)
>>> type(ind)
<type 'numpy.int32'>
>>> type(ind) is type(numpy.int32)
False
>>> id(type(ind))
1810415712
>>> id(type(numpy.int32))
505314840
The solution I guess is to eliminate the explicit type checking as per Alan's
previously posted code.
-Dave
More information about the Scipy-dev
mailing list