[英]Best way to create array with a range of number (Double Type) in Scala
I want to create a range number for an array. 我想为数组创建一个范围号。 The data type is Double, not Int.
数据类型为Double,而不是Int。 it looks like:
[1.0,2.0,3.0,4.0....]
它看起来像:
[1.0,2.0,3.0,4.0....]
Now I am doing like 现在我在做
val arraydataInt=1 to 1000 toArray
val arraydata = arraydataInt.map(x=>x.toDouble)
I am just not sure if the way is efficient. 我只是不确定这种方式是否有效。
Iterate or tabulate, take your pick. 迭代或制表,随便选择。
Array.iterate(1.0,1000)(1.+)
// or
Array.tabulate(1000)(1.0.+)
在范围内使用双打
1d to 1000d by 1d toArray
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.