有没有一种方法可以从数组中删除负值?

时间:2020-04-08 16:59:41

标签: ruby

如果我有类似的东西:

# 2020-04-08 12:33:17 EDT: Estimating execution time using 2% of 590400 = 11808 Error : == irace == running command ''.../tuning/target-runner' 1 1 1042861479 .../tuning/Instances/README 9 11728 0.6487 0.8525 226 2>&1' had status 1 == irace == The call to targetRunner was: .../tuning/target-runner 1 1 1042861479 .../tuning/Instances/README 9 11728 0.6487 0.8525 226 == irace == The output was: .../tuning/target-runner: line 57: 74728 Killed Rscript .../tblupcpp.r ${CONFIG_PARAMS} > ${STDOUT} 2> ${STDERR} Wed Apr 8 16:34:10 UTC 2020: .../tuning/target-runner: error: out30304.txt: No such file or directory == irace == This is not a bug in irace, but means that something failed when running the command(s) above or they were terminated before completion. Try to run the command(s) above from the execution directory '.../solvers' to investigate the issue. See also Appendix B (targetRunner troubleshooting checklist) of the User Guide (https://cran.r-project.org/package=irace/vignettes/irace-package.pdf). Error : == irace == running command ''.../tuning/target-runner' 3 1 1042861479 .../tuning/Instances/README 8 18796 0.5252 0.5963 327 2>&1' had status 1 == irace == The call to targetRunner was: .../tuning/target-runner 3 1 1042861479 .../tuning/Instances/README 8 18796 0.5252 0.5963 327 == irace == The output was: .../tuning/target-runner: line 57: 74727 Killed Rscript .../tblupcpp.r ${CONFIG_PARAMS} > ${STDOUT} 2> ${STDERR} Wed Apr 8 16:34:04 UTC 2020: .../tuning/target-runner: error: out22101.txt: No such file or directory == irace == This is not a bug in irace, but means that something failed when running the command(s) above or they were terminated before completion. Try to run the command(s) above from the execution directory '.../solvers' to investigate the issue. See also Appendix B (targetRunner troubleshooting checklist) of the User Guide (https://cran.r-project.org/package=irace/vignettes/irace-package.pdf). Error: == irace == A child process triggered a fatal error In addition: Warning message: In parallel::mclapply(experiments, exec.target.runner, mc.preschedule = !scenario$loadBalancing, : 2 function calls resulted in an error Execution halted

我想回来

numbers = [2, 88, 0.5, -23.55, 0, -45000]

2 个答案:

答案 0 :(得分:3)

使用selectreject

numbers.select { |number| number >= 0 }

numbers.reject(&:negative?)

答案 1 :(得分:0)

您可以使用强大的(但经常被忽视和低估)Enumerable#grep

numbers.grep 0..Float::INFINITY
  #=> [2, 88, 0.5, 0] 

numbers.grep 0..1/0.0