1

It seems as if I have to import scipy optimize explicitly to get it. An example: If I do

 import scipy as sp
 sp.optimize.somefunction()

I get an AttributeError. But if I do

 import scipy as sp
 from scipy import optimize
 sp.optimize.somefunction()

Everything works fine.

Is this desired behaviour? How do I enforce python to load the whole namespace of scipy by doing import scipy as sp?

mcocdawc
  • 1,748
  • 1
  • 12
  • 21

1 Answers1

3

You don't. The import directives in scipy don't allow that. By design it is modular. You have to use the from scipy import optimize kind of statements.

With from scipy import optimize you can then use optimize.somefunction().

This has been raised a number of times before. A good duplicate is

Why does from scipy import spatial work, while scipy.spatial doesn't work after import scipy?

Community
  • 1
  • 1
hpaulj
  • 221,503
  • 14
  • 230
  • 353