姬長信(Redy)

python – 从CSV文件中的Adjacency Matrix绘制Net…


我现在一直在与这个问题作斗争,我知道这很简单 – 但我对Python或NetworkX没什么经验.我的问题非常简单,我试图绘制一个大型数据集(大约200行/列)的矩阵,看起来像这样.第一行和第一列是相同的.
  A,B,C,D,E,F,G,H,I,J,K
A,0,1,1,0,1,1,1,1,0,1,0
B,1,0,0,0,1,1,1,1,0,1,0
C,1,0,0,0,1,1,1,1,0,1,0

它只是一个显示人们如何连接的矩阵,我想要的只是导入和绘制这个csv文件,并在NetworkX中使用它的相应标签.

我有这个文件(people.csv),并查看以前的答案here,这似乎是最好的方法是将数据放入一个numpy数组.

这似乎有一个问题:

import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from numpy import genfromtxt
import numpy as np

mydata = genfromtxt('mouse.csv', delimiter=',')

我得到以下输出:

File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/npyio.py", line 1272, in genfromtxt
  fhd = iter(np.lib._datasource.open(fname, 'rbU'))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/_datasource.py", line 145, in open
  return ds.open(path, mode)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/_datasource.py", line 472, in open
  found = self._findfile(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/_datasource.py", line 323, in _findfile
  if self.exists(name):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/_datasource.py", line 417, in exists
  from urllib2 import urlopen
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 94, in 
  import httplib
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 69, in 
  from array import array
      File "/Users/Plosslab/Documents/PythonStuff/array.py", line 4, in 
      NameError: name 'array' is not defined