|
5鱼币
问题如下:
(1)由于我处理的数据太多了,代码编译出来会出现错误:too many values to unpacked。这个我该怎么处理?
(2)我需要对数据按照一种公式进行处理,但是有一些数据按照公式运算会出现错误(比如有的数据会出现负数取对数),我如何把这些出错的数据舍弃掉并留下我需要的数据而且不让程序报错呢?
代码:
- import numpy as np
- import math
- with open("E:\\33.txt") as f:
- data_str=[eachline.split() for eachline in f]
- x_str, y_str = zip(data_str)
- x_numeric = np.array([float(x) for x in x_str])
- y_numeric = np.array([float(y) for y in y_str])
- print(x_numeric)
- print(y_numeric)
- print('Please input a constant')
- a=float(input())
- b=y_numeric[:240]
- print(sum(b))
- for i in y_numeric[250:2500]:
- i=math.log((((sum(b)/6)-a)/(i-a)),10)
- q=math.log(i)
- print(q)
复制代码
在你运算之前就已经报错了。。见我之前的回答
http://bbs.fishc.com/forum.php?mod=redirect&goto=findpost&ptid=82623&pid=2799391
如果要过滤数据,可以使用python内置的filter()方法
filter(function, iterable)
Construct an iterator from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.
|
-
最佳答案
查看完整内容
在你运算之前就已经报错了。。见我之前的回答
http://bbs.fishc.com/forum.php?mod=redirect&goto=findpost&ptid=82623&pid=2799391
如果要过滤数据,可以使用python内置的filter()方法
|