ValueError:在尝试解压缩simple.txt文件时,要解压缩的值太多

时间:2016-09-17 05:48:44

标签: python numpy

我有这个简单的代码来读取和绘制.txt文件

import sys
import os
import numpy
import matplotlib.pyplot as plt
from pylab import *

exp_sum = 'exponential_sum.txt'

Term, Absolute_error, Relative_error= numpy.loadtxt(exp_sum, unpack =True)

plt.semilogy(Term,Absolute_error, 'm^-')
plt.semilogy(Term,Relative_error, 'g-')


xlabel('Number of terms N')
ylabel('Absolute and Relative approximation error')
legend(['Absolute error', 'relative error'], loc = 'upper right')
title('Testing convergence of exponential series with respect to error vs iteration terms')
show()

到目前为止工作得很好,现在它只是在尝试绘制这个简单的文本文件时给了我这个奇怪的错误。请帮我解决这个值错误,也附上.txt文件。

#Term   Exponential_sum    Absolute_error       Relative_error       
0       1.0                1.71828182846        0.632120558829       
1       2.0                0.718281828459       0.264241117657       
2       2.5                0.218281828459       0.0803013970714      
3       2.66666666667      0.0516151617924      0.0189881568762      
4       2.70833333333      0.00994849512571     0.00365984682734     
5       2.71666666667      0.00161516179238     0.000594184817582    
6       2.71805555556      0.00022627290349     8.3241149288e-05     
7       2.71825396825      2.78602050767e-05    1.02491966745e-05    
8       2.71827876984      3.05861777505e-06    1.12520259784e-06    
9       2.71828152557      3.02885852843e-07    1.11425478283e-07    
10      2.71828180115      2.73126605776e-08    1.00477663102e-08    
11      2.7182818262       2.26055218988e-09    8.31610676352e-10    
12      2.71828182829      1.72876379878e-10    6.35976660213e-11    
13      2.71828182845      1.22857279905e-11    4.51966674753e-12    
14      2.71828182846      8.14903700075e-13    2.99786317792e-13    
15      2.71828182846      5.01820807131e-14    1.84609558095e-14    
16      2.71828182846      2.22044604925e-15    8.1685645175e-16     
17      2.71828182846      4.4408920985e-16     1.6337129035e-16     
18      2.71828182846      4.4408920985e-16     1.6337129035e-16     
19      2.71828182846      4.4408920985e-16     1.6337129035e-16

1 个答案:

答案 0 :(得分:1)

您正尝试将四列拆分为三个变量 - Exponential_sum变量缺失!