1

I am using scipy.optimize.minimize for my algorithm. I use scipy 0.16.1, Eclpise LUNA and PyDev.

When my code is:

import scipy as sp
optim = sp.optimize.minimize(func,x0 = x0,args = (X,Y,Z))
print optim
print optim.x

The print optim works fine, but I got a warning underlying optimize as: Undefined variable from import: optimize. And I got an error when running the code print optim.x AttributeError: 'tuple' object has no attribute 'x'

However, when I change my code to:

import scipy as sp
import scipy.optimize as spo
optim = spo.minimize(func,x0 = x0,args = (X,Y,Z))
print optim
print optim.x

It works fine. But, I do not have auto completion when I type print optim. for x

So here are my questions:

  1. Why import scipy as sp with sp.optimize.minimize gives a warning?

  2. Why there is no auto completion for optim.?

jkalden
  • 1,548
  • 4
  • 24
  • 26
flyingmouse
  • 1,014
  • 3
  • 13
  • 29
  • The problem seems to be within Eclipse/Pydev, as the code works as expected! I see the same here for scipy 0.14 with Eclipse Kepler and PyDev 2.3... – jkalden Nov 03 '15 at 12:04
  • @flyingmouse It might not be obvious, but this question is a duplicate. See the question that I marked it as duplicating, along with http://stackoverflow.com/questions/21071715/why-does-from-scipy-import-spatial-work-while-scipy-spatial-doesnt-work-after; there are probably still more questions in stackoverflow that are basically about the same issue. In short, you *must* explicitly import `scipy.optimize`. If you only `import scipy`, the `optimize` subpackage is not imported. – Warren Weckesser Nov 04 '15 at 19:11

0 Answers0