scipy.signal not defined, but works after importing skimage

Question:

I would like to use scipy.signal.convolve2d() function from SciPy, but signal is undefined:

>>> import scipy
...
>>> conv = scipy.signal.convolve2d(data, kernel, mode="same")

Error: Traceback (most recent call last):
  File "test.py", line n, in <module>
    conv = scipy.signal.convolve2d(data, kernel, mode="same")
AttributeError: module 'scipy' has no attribute 'signal'.

But when I add skimage import:

from skimage.morphology import square

or

from skimage.morphology import disk

It suddenly starts to be defined, and works fine. Any ideas why and how to fix it properly, so it wouldn’t need unused import? Skimage is a totally different thing, not related (at least in theory).

Lib versions:

scikit-image              0.19.2           py37hf11a4ad_0    anaconda
scikit-learn              1.0.2            py37hf11a4ad_1
scipy                     1.7.3            py37h0a974cb_0

Python version:

Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
Asked By: Flash Thunder

||

Answers:

Use

import scipy.signal

to make sure you import the SciPy Signal subpackage.

import skimage probably imports scipy.signal under the hood, so the subpackage is available in the namespace; normally, you need to do this yourself.

Answered By: 9769953
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.