# How to convert Tuples to Arrays

**URL:** <https://discourse.julialang.org/t/how-to-convert-tuples-to-arrays/2890>\
**Category:** New to Julia\
**Created:** [March 26, 2017, 11:11pm UTC](https://discourse.julialang.org/t/how-to-convert-tuples-to-arrays/2890 "2017-03-26T23:11:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![josimar](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@josimar](https://discourse.julialang.org/u/josimar)\
**Post date:** [March 26, 2017, 11:11pm UTC](https://discourse.julialang.org/t/how-to-convert-tuples-to-arrays/2890/1 "2017-03-26T23:11:30Z")

</div>

Hi,

I am trying to understand better the concept of Tuples and Array, and how to convert Tuples to Arrays.

This is What I am doing:

> Using StatsBase  
> h=fit(Histogram,rand(100),0:0.01:1)  
> e=z.edges  
> typeof(e)  
> Tuple{FloatRange{Float64}}

> # Convert to array here  
> x=collect(e)  
> typeof(x)  
> Vector{FloatRange{Float64},1}

I dont understand the following:

If I try “length(x)” I get the value 1, where I was actually expecting 101.

In order to obtain 101 I have to do “size(x[:][1])” . Why ?

How to convert the Tuple to Array in order to access its elements ?

thank you

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [March 27, 2017, 12:42am UTC](https://discourse.julialang.org/t/how-to-convert-tuples-to-arrays/2890/2 "2017-03-27T00:42:23Z")

</div>

`h.edges` is a one-element tuple, `(0.0:0.01:1.0,)`, whose only element `h.edges[1] == 0.0:0.01:1.0` is a range from 0 to 1.0. If you collect the one-element tuple, you get a one-element array, whereas collecting the range `h.edges[1]` expands it into the 101-element array you’ve seen.

As for why `h.edges` is a one-element tuple of range, rather than just a range, you’d have to read the docs to understand that, but it’s undoubtedly this way because sometimes `h.edges` will be more than just one range (maybe if the input is an N-dimensional arrays, it will return N ranges).

Does that help?

---

<div class="post-metadata">

**Author:** ![josimar](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@josimar](https://discourse.julialang.org/u/josimar)\
**Post date:** [March 27, 2017, 1:13am UTC](https://discourse.julialang.org/t/how-to-convert-tuples-to-arrays/2890/3 "2017-03-27T01:13:16Z")

</div>

Yes it helps a lot ! thank you so much !
