鱼C论坛

 找回密码
 立即注册
查看: 1939|回复: 1

[已解决]如何舍弃不需要的数据?

[复制链接]
发表于 2017-2-15 17:30:20 | 显示全部楼层 |阅读模式
5鱼币
CIM8SEUKI7GDW5GHX@HO7BD.png
问题如下:
(1)由于我处理的数据太多了,代码编译出来会出现错误:too many values to unpacked。这个我该怎么处理?
(2)我需要对数据按照一种公式进行处理,但是有一些数据按照公式运算会出现错误(比如有的数据会出现负数取对数),我如何把这些出错的数据舍弃掉并留下我需要的数据而且不让程序报错呢?
代码:
  1. import numpy as np
  2. import math
  3. with open("E:\\33.txt") as f:
  4.     data_str=[eachline.split() for eachline in f]
  5. x_str, y_str = zip(data_str)
  6. x_numeric = np.array([float(x) for x in x_str])
  7. y_numeric = np.array([float(y) for y in y_str])
  8. print(x_numeric)
  9. print(y_numeric)
  10. print('Please input a constant')
  11. a=float(input())
  12. b=y_numeric[:240]
  13. print(sum(b))
  14. for i in y_numeric[250:2500]:
  15.     i=math.log((((sum(b)/6)-a)/(i-a)),10)
  16.     q=math.log(i)
  17.     print(q)
复制代码
最佳答案
2017-2-15 17:30:21
在你运算之前就已经报错了。。见我之前的回答
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.

L1WD5GG51M(WGQ(]EI76)N3.png

最佳答案

查看完整内容

在你运算之前就已经报错了。。见我之前的回答 http://bbs.fishc.com/forum.php?mod=redirect&goto=findpost&ptid=82623&pid=2799391 如果要过滤数据,可以使用python内置的filter()方法
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-2-15 17:30:21 | 显示全部楼层    本楼为最佳答案   
在你运算之前就已经报错了。。见我之前的回答
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.

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-27 17:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表