# Create array from range values

**URL:** <https://discourse.julialang.org/t/create-array-from-range-values/21656>\
**Category:** New to Julia\
**Created:** [March 9, 2019, 1:45am UTC](https://discourse.julialang.org/t/create-array-from-range-values/21656 "2019-03-09T01:45:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elmer\_Cusipuma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmer_cusipuma/32/11958_2.png) [@Elmer\_Cusipuma](https://discourse.julialang.org/u/Elmer_Cusipuma)\
**Post date:** [March 9, 2019, 1:45am UTC](https://discourse.julialang.org/t/create-array-from-range-values/21656/1 "2019-03-09T01:45:20Z")

</div>

I’m trying create a array from ranges in Julia 1.1.

```julia
lb = [0,0,0,0,0,0,0];
ub = [4,4,4,2,2,2,6];

range.(lb,ub)
UnitRange{Int64}[7]
0:4
0:4
0:4
0:2
0:2
0:2
0:6

```

Getting this message when I run test

```julia
┌ Warning: `range(start, stop)` (with neither `length` nor `step` given) is deprecated, use `range(start, stop=stop)` instead.
│ caller = _broadcast_getindex_evalf at broadcast.jl:578 [inlined]
└ @ Core .\broadcast.jl:578

```

But for some reason, I cannot create the array when expressed this way:

```julia
range.(lb,stop=ub)
MethodError: no method matching (::Colon)(::Int64, ::Array{Int64,1})

```

---

<div class="post-metadata">

**Author:** ![aharoun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aharoun/32/6887_2.png) [@aharoun](https://discourse.julialang.org/u/aharoun)\
**Post date:** [March 9, 2019, 1:54am UTC](https://discourse.julialang.org/t/create-array-from-range-values/21656/2 "2019-03-09T01:54:03Z")

</div>

I believe dot notation does not broadcast over keyword arguments.  
But for your example, you can do this:

```julia
julia> lb = [0,0,0,0,0,0,0];
julia> ub = [4,4,4,2,2,2,6];

julia> range.(lb, ub, step=1)
7-element Array{StepRange{Int64,Int64},1}:
 0:1:4
 0:1:4
 0:1:4
 0:1:2
 0:1:2
 0:1:2
 0:1:6

```

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [March 9, 2019, 2:27am UTC](https://discourse.julialang.org/t/create-array-from-range-values/21656/3 "2019-03-09T02:27:27Z")

</div>

Good suggestion! However, it creates a `StepRange`, not a `UnitRange`. For most applications that’s probably fine, but it has slightly worse performance, and could potentially throw off code specialized for unit ranges. If you know that you always want `UnitRange`s, you could use that directly:

```julia
julia> lb = [0,0,0,0,0,0,0];

julia> ub = [4,4,4,2,2,2,6];

julia> UnitRange.(lb, ub)
7-element Array{UnitRange{Int64},1}:
 0:4
 0:4
 0:4
 0:2
 0:2
 0:2
 0:6

```

If you want to use the colon notation for more flexibility, you can use `zip`:

```julia
julia> [z[1]:z[2] for z in zip(lb, ub)]
7-element Array{UnitRange{Int64},1}:
 0:4
 0:4
 0:4
 0:2
 0:2
 0:2
 0:6

```

Some alternative forms below that do the same thing… some people prefer one syntax over the other:

```julia
julia> zip(lb, ub) .|> z -> z[1]:z[2]
7-element Array{UnitRange{Int64},1}:
...

julia> map(z -> z[1]:z[2], zip(lb, ub))
7-element Array{UnitRange{Int64},1}:
...

julia> (z -> z[1]:z[2]).(zip(lb, ub))
7-element Array{UnitRange{Int64},1}:
...

```
