From d67d31cd27c42b3503449dc22c4e1e67a99334ed Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Thu, 9 Apr 2015 00:41:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B2=A1=E5=86=99=E5=AE=8C=E8=AF=BB=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- .gitignore | 2 ++ pso.py | 7 +++++++ reader.py | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 pso.py create mode 100644 reader.py diff --git a/.gitignore b/.gitignore index e69de29..a47fb1d 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +__pycache__ \ No newline at end of file diff --git a/pso.py b/pso.py new file mode 100644 index 0000000..d2fba08 --- /dev/null +++ b/pso.py @@ -0,0 +1,7 @@ +__author__ = 'dmy' + +from reader import * + +if __name__=='__main__': + ieeeData=IEEEData('IEEE4.dat') + print('Finished.') \ No newline at end of file diff --git a/reader.py b/reader.py new file mode 100644 index 0000000..55811cc --- /dev/null +++ b/reader.py @@ -0,0 +1,26 @@ +__author__ = 'dmy' + +import numpy + +class IEEEData: + def __init__(self,filePath,seperator='\t'): + self._filePath=filePath + self._seperator=seperator + self._read() + def _convertToVector(self,lineVec):#把数据文件按分隔符存成矩阵,像Matlab一样。 + self._array=numpy.array(lineVec) + print(lineVec) + print(self._array[0]) + + def _read(self): + lineVec=[] + with open(self._filePath,'tr') as f: + for line in f: + if len(line.strip())==0: + continue + lineVec.append([float(x) for x in line.split(self._seperator)]) + self._convertToVector(lineVec) + + + +