Reputation: 469
According to documentation, there should be a null_space
function in the scipy.linalg
package. I am using python3, but I can not import the function:
import scipy.linalg.null_space as null
Traceback (most recent call last):
File "<ipython-input-142-eb3cbfa6f87d>", line 1, in <module>
import scipy.linalg.null_space as null
ImportError: No module named 'scipy.linalg.null_space'
Is this not strange? What is wrong here? I also can import scipy itself just fine.
Upvotes: 1
Views: 933
Reputation: 114440
There are two problems here. The first is that null_space
wasn't added to scipy until version 1.1.0. The release notes mention this explicitly.
You have two workarounds available in this regard. The simplest in the long run is to simply upgrade scipy. The other is to copy the function out of scipy/linalg/decomp_svd.py
:333 on GitHub, stick it in your utilities somewhere, and use that.
The second issue is your import syntax. An import statement of the form import x as y
only works when x
is a module. To import a module attribute, you need to use from x import a [as b]
notation:
from scipy.linalg import null_space
null_space(...)
Alternatively, you can use import x [as y]
notation, to access the attribute through the module:
import scipy.linalg.null_space
scipy.linalg.null_space(...)
Or
import scipy.linalg as la
la.null_space(...)
The error message pretty much tells you exactly what the problem is, but it's a little cryptic if you don't already know what to look for.
Upvotes: 2