Ich habe Matrix von Signalen in Matlab (24 x 121) und Etiketten-Datei (1x 24) generiert. Nachdem ich es geladen wird, ist es: EtikettenPython Graph von Matrix mit Etiketten erzeugt bei Matlab
[array(['1-2'],
dtype='<U3') array(['1-3'],
dtype='<U3')
array(['1-4'],
dtype='<U3') array(['2-2'],
dtype='<U3')
array(['2-3'],
dtype='<U3') array(['2-4'],
dtype='<U3')
array(['49-2'],
dtype='<U4') array(['49-3'],
dtype='<U4')
array(['49-4'],
dtype='<U4') array(['50-2'],
dtype='<U4')
array(['50-3'],
dtype='<U4') array(['50-4'],
dtype='<U4')
array(['51-2'],
dtype='<U4') array(['51-3'],
dtype='<U4')
array(['51-4'],
dtype='<U4') array(['52-2'],
dtype='<U4')
array(['52-3'],
dtype='<U4') array(['52-4'],
dtype='<U4')
array(['53-2'],
dtype='<U4') array(['53-3'],
dtype='<U4')
array(['53-4'],
dtype='<U4') array(['54-2'],
dtype='<U4')
array(['54-3'],
dtype='<U4') array(['54-4'],
dtype='<U4')]
und X
[[ 1.31973026 1.04553767 0.98759242 ..., 0.87344433 0.8734996
0.88148139]
[ 1.54466891 1.50167134 1.43233076 ..., 0.71953425 0.72355352
0.76595696]
[ 0.26974139 0.27669694 0.26486576 ..., 0.86765017 0.84838513
0.83147331]
...,
[ 1.28762992 1.21298643 1.08822084 ..., 0.81903216 0.7559759
0.62566092]
[ 0.96190193 0.97199575 0.93630357 ..., 0.88570213 0.78969704
0.69140163]
[ 1.70054223 1.6876721 1.66986342 ..., 0.90825585 0.92562056
0.93568893]]
Ich möchte Grafik 1-Korrelationsmaß Ähnlichkeit zum Zeichnen und nicht Zweig zeigen, wenn es Gewicht> 0,7. Der Code Ich verwende ist:
import scipy.io
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm # Large set of colormaps
import pandas as pd
from scipy.cluster import hierarchy
from sklearn import datasets
from sklearn import metrics
from sklearn import cluster
from scipy.spatial.distance import pdist
import networkx as nx
from matplotlib import pyplot as plt
import pylab
import networkx as nx
from matplotlib import pyplot as plt
o1 = scipy.io.loadmat('out.mat')
X=(o1['out'])
print(X)
o1 = scipy.io.loadmat('labels.mat')
labels=o1['labels']
labels = labels[0]
print(labels)
corr=1-np.corrcoef(X)
print(corr)
m, n = np.shape(corr)
G = nx.Graph()
corr[np.where(corr>0.7)]=0
for i in range(m):
for j in range(n):
s=labels[i]
b=labels[j]
w=corr[i,j]
G.add_edge(s,b,weight=w)
nx.draw(G)
plt.show()
ich einen Fehler
Traceback (most recent call last): File "C:/Users/Kristina/Desktop/NOBS/source/grafovi.py", line 36, in G.add_edge(s,b,weight=w) File "C:\Python34\lib\site-packages\networkx\classes\graph.py", line 706, in add_edge if u not in self.node: TypeError: unhashable type: 'numpy.ndarray'
ich kann nicht herausfinden, was das Problem ist.
Vielleicht sind s und b Listen und 'G.add_edge' will etwas anderes (z. B. ein Tupel). Listen sind nicht hashbar. Alle unveränderlichen Objekte sind hashbar (Typle etc.). Siehe: https://docs.python.org/3/glossary.html und suche nach "hashable" Wenn "G.add_edge" ein Wörterbuch erstellen und entweder s und b als Schlüssel verwenden möchte, muss es hashbar sein. – Moritz