Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's Julia's equivalent of R's seq(..., length.out = n)

Tags:

r

julia

I can see from this link that R's equivalent of seq is n:m in (http://www.johnmyleswhite.com/notebook/2012/04/09/comparing-julia-and-rs-vocabularies/).

But the case of seq(a,b, length.out = n) is not covered.

For example seq(1, 6, length.out=3) gives c(1.0, 3.5, 6.0). It is a really nice way to specify the number of outputs.

What's its equivalent in Julia?

like image 864
xiaodai Avatar asked Jan 22 '18 23:01

xiaodai


1 Answers

As of Julia 1.0:

linspace has been deprecated. You can still use range:

julia> range(0, stop = 5, length = 3)
0.0:2.5:5.0

As @TasosPapastylianou noted, if you want this to be a vector of values, you can use collect:

julia> collect( range(0, stop = 5, length = 3) )
3-element Array{Float64,1}:
0.0
2.5
5.0
like image 114
Cliff AB Avatar answered Oct 17 '22 00:10

Cliff AB