1
votes

there, I am a newbie of python 2.7. I have a quick question about importing modules. When doing hierarchical clustering I need a module named dendrogram. I saw the coding on the internet works well which has this line: "import from scipy.cluster.hierarchy import dendrogram, linkage". However, when I changed this line to "import scipy" the code failed and the IDE displays "name linkage is not defined". Why only importing scipy does not work? Does module scipy include all modules such as dendrogram, linkage, etc?

Thank you!

1

1 Answers

4
votes

The correct syntax is:

from scipy.cluster.hierarchy import dendrogram, linkage

dendogram and linkage functions are in the scipy.cluster.hierarchy module as can be seen in the scipy.cluster.hierarchy reference. This will make the dendrogam and linkage functions available in the current module you are writing.

If you only use:

import scipy

you will have to use the full name of the function like:

scipy.cluster.hierarchy.linkage