注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

阿弥陀佛

街树飘影未见尘 潭月潜水了无声 般若观照心空静...

 
 
 

日志

 
 
关于我

一直从事气象预报、服务建模实践应用。 注重气象物理场、实况场、地理信息、本体知识库、分布式气象内容管理系统建立。 对Barnes客观分析, 小波,计算神经网络、信任传播、贝叶斯推理、专家系统、网络本体语言有一定体会。 一直使用Java、Delphi、Prolog、SQL编程。

网易考拉推荐

scala to 必须过滤NaN  

2015-05-19 16:58:35|  分类: Scala |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
package nc4.test

/**
* Created by hxf on 15-5-19.
*/
object SMTest {
import scala.collection.immutable.SortedMap
def main(args: Array[String]) {
//,Double.NaN,Double.NaN
val arr = Array(
51.94336,52.910156,53.9209,54.887695,55.854492,56.865234,57.875977,58.88672,59.89746,60.908203,61.918945,62.929688,63.896484,
64.90723,65.83008,66.708984,67.67578,68.55469,69.43359,70.356445,71.32324,72.29004,73.30078,74.35547,75.41016,76.46484,77.56348,
78.57422,79.58496,80.63965,81.5625,82.48535,83.36426,84.19922,85.12207,86.00098,86.92383,87.84668,88.90137,89.91211,90.92285,91.97754,
92.98828,94.04297,95.09766,96.15234,97.11914,98.12988,99.052734,100.01953,100.94238,101.865234,102.83203,103.79883,104.80957,105.82031,
106.831055,107.8418,108.896484,109.95117,110.961914,111.884766,112.89551,113.862305,114.74121,115.62012,116.45508,117.37793,118.256836,
119.13574,120.10254,121.069336,122.12402,123.134766,124.18945,125.24414,126.29883,127.39746,128.32031,129.375,130.2539,131.17676,
132.05566,132.89062,133.76953,134.69238,135.61523,136.58203,137.54883,138.60352,139.61426,140.66895,141.72363,142.77832,143.83301,
144.7998,145.85449,146.86523,147.78809,148.75488,149.67773,150.60059,151.52344,152.44629,153.36914,154.29199,155.25879,156.26953,
157.28027,158.24707,159.30176,160.35645,161.36719,162.42188,163.43262,164.4873,165.4541,166.37695,167.34375,168.22266,169.05762,
169.89258,170.81543,171.65039,172.57324,173.54004,174.55078,175.56152,176.61621,177.71484,178.81348,179.86816,180.92285,181.88965,
182.85645,183.73535,184.57031,185.44922,186.24023,187.16309,188.08594,189.00879,189.97559,191.03027,192.08496,193.1836,194.23828,195.29297,
196.34766,197.40234,198.36914,199.33594,200.21484,201.1377,202.0166,202.89551,203.81836,204.78516,205.75195,206.80664,207.81738,208.87207,
209.88281,210.9375,211.99219,213.04688,214.05762,215.02441,216.03516,216.95801,217.83691,218.67188,219.59473,220.42969,221.3086,222.27539,
223.24219,224.29688,225.35156,226.40625,227.50488,228.60352,229.6582,230.625,231.5918,232.51465,233.34961,234.22852,235.06348,
235.89844,236.82129,237.74414,238.71094,239.72168,240.73242,241.78711,242.79785,243.89648,244.99512,246.00586,247.0166,247.9834,
248.9502,249.87305,250.7959,251.71875,252.59766,253.56445,254.4873,255.49805,256.46484,257.51953,258.53027,259.54102,260.55176,
261.60645,262.66113,263.67188,264.63867,265.6494,266.6162,267.49512,268.37402,269.25293,270.13184,271.01074,271.97754,272.9004,
273.8672,274.92188,275.93262,276.9873,278.042,279.09668,280.15137,281.20605,282.17285,283.0957,284.01855,284.89746,285.77637,
286.65527,287.49023,288.45703,289.37988,290.39062,291.40137,292.45605,293.4668,294.56543,295.62012,296.6748,297.68555,298.74023,
299.75098,300.67383,301.64062,302.56348,303.44238,304.27734,305.24414,306.167,307.1338,308.1006,309.11133,310.12207,311.17676,
312.1875,313.2422,314.29688,315.35156,316.3623,317.3291,318.33984,319.1748,320.0537,320.88867,321.72363,322.64648,323.5254,324.44824,
325.45898,326.42578,327.48047,328.53516,329.6338,330.68848,331.7871,332.79785,333.8086,334.73145,335.6543,336.5332,337.36816,338.20312,
339.08203,339.96094,340.8838,341.8506,342.86133,343.91602,344.9707,346.06934,347.12402,348.22266,349.27734,350.33203,351.29883,352.26562,
353.1006,354.02344,354.90234,355.78125,356.7041,357.62695,358.59375,359.6045,0.6152344,1.6259766,2.680664,3.6914062,4.790039,5.8007812,
6.8554688,7.8222656,8.7890625,9.711914,10.59082,11.469727,12.3046875,13.183594,14.106445,15.073242,16.04004,17.138672,18.149414,19.248047,
20.34668,21.401367,22.456055,23.466797,24.389648,25.3125,26.14746,26.982422,27.861328,28.740234,29.61914,30.585938,31.552734,32.60742,33.66211,
34.716797,35.771484,36.870117,37.924805,38.935547,39.902344,40.86914,41.791992,42.6709,43.59375,44.5166,45.439453,46.362305,47.373047,48.339844,
49.350586,50.405273,51.416016,Double.NaN,Double.NaN
)
val azp = arr.zipWithIndex.toMap
val smap = SortedMap.empty[Double,Int] ++ azp
val a = 0.5
val amin = smap.keys.head
val imin = smap(amin)
println("amin="+amin +"-->"+imin)

val amax = smap.keys.last
val imax = smap(amax)
println("amax="+amax +"-->"+imax)

val aidx = smap.to(a).last
println(aidx)
}
}
amin=0.6152344-->317
amax=NaN-->371
Exception in thread "main" java.util.NoSuchElementException: empty map
at scala.collection.immutable.RedBlackTree$.greatest(RedBlackTree.scala:90)
at scala.collection.immutable.TreeMap.last(TreeMap.scala:77)
at scala.collection.immutable.TreeMap.last(TreeMap.scala:48)
at nc4.test.SMTest$.main(SMTest.scala:51)
at nc4.test.SMTest.main(SMTest.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Process finished with exit code 1


  评论这张
 
阅读(973)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017