错误转换为浮动蟒蛇,其他人似乎没有得到

问题描述 投票:-1回答:2

我试着从一个文本文件,绘制数据,我不断收到此错误。

Traceback (most recent call last):
  File "C:/Users/User/Desktop/photonics/photon test n stuff/copying 7a from paper 2/wont work.py", line 15, in <module>
    T.append(float(lines[x].strip()))
ValueError: could not convert string to float: '9.17973518E'

我一打听,其他人都告诉我,他们没有得到错误。

https://www.chegg.com/homework-help/questions-and-answers/python-converting-exponential-im-getting-error-r-2-545454py-line-18-tappend-float-lines-x--q34639464

https://www.chegg.com/homework-help/questions-and-answers/python-lists-reading-files-im-trying-make-list-1-r-t-use-first-500-values-r-t-different-le-q34610346

我的继承人完整的代码。

import numpy
import matplotlib.pyplot as plt
################################### making R list
f=open('R 77777.txt',"r")
lines=f.readlines()
R=[]
for x in range(500):
    R.append(float(lines[x].strip()))
f.close()
################################### making T list
f=open('T 77777.txt',"r")
lines=f.readlines()
T=[]
for x in range(500):
    T.append(float(lines[x].strip()))
f.close()
################################## each A = 1 - R[i] - T[i]
A=[]
for i in range(len(R)):
    A.append(1 - (R[i]) - (T[i]))
K=numpy.linspace(0,100,500)
#print(K)
plt.plot(K, A)
plt.title("K over A")
plt.figure()
plt.plot(K, R)
plt.title( " R = Y, K = x ")
plt.show()

我的继承人的数据。

找到https://pastebin.com/y2Uby5eF牛逼名单

找到https://pastebin.com/nX2Y6TVH [R名单

为什么会出现这个问题,但不是别人?

python exponential
2个回答
1
投票

能尚未对此发表评论:字符串浮越来越没有任何编号:E之后,所以它可能不会将其视为科学记数法。


0
投票

你的一些数据是在科学记数法。

在Python浮子()函数有一些麻烦与此类型的输入。

为了这个正常工作,你需要保留的后缀。

x = "9.17973518E-02"

float(x)
© www.soinside.com 2019 - 2024. All rights reserved.