0
.dat 파일에서 일부 시뮬레이션 결과를 읽고 분석하려고합니다.문자열 배열을 부동 배열로 변환
N o d a l D i s p l a c e m e n t s Time 0.10000E+01
Prop. Ld. 1.00000E+00
Node 1 Coord 2 Coord 3 Coord 1 Displ 2 Displ 3 Displ
1 0.0000E+00 5.0000E-01 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00
2 0.0000E+00 2.5005E-01 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00
3 0.0000E+00 1.0000E-04 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00
4 1.0000E+00 5.0000E-01 0.0000E+00 -1.9511E-04 4.0845E-04 -2.1522E-05
5 1.0000E+00 2.5005E-01 0.0000E+00 1.1185E-08 4.0053E-04 2.6545E-09
6 1.0000E+00 1.0000E-04 0.0000E+00 1.9511E-04 4.0847E-04 2.1526E-05
7 2.0000E+00 5.0000E-01 0.0000E+00 -3.5177E-04 1.5287E-03 -1.2678E-05
... 그래서 하나 파일 구조 다음있다.
숫자 데이터를 실수로 변환하여 문자열을 삭제할 수 있습니까? 나는 다음과 같은 코드로 시도 :
class DataLoader:
def __init__(self, number_files):
self.number_files = number_files
def loader(self):
array = []
for i in range(1, self.number_files + 1):
try:
if i < 10:
data = open("ndis_00%s.dat" % i, "r")
elif i >= 10 and i <= 100:
data = open("ndis_0%s.dat" % i, "r")
except IOError:
print("I/O Error")
for line in data:
if line != "\n":
array.append(line.split())
try:
float(line)
except (ValueError, TypeError):
line[:] = []
print(line)
을 내가 떠 변환 선을 유지하려는 코드와 완전히 삭제할 수 있습니다 변환하지 않습니다 문자열에서.
감사합니다. 그게 전부 야. – ingenium