Changing number format when concatenating

I have an integer Array a=[1,2,3,4] and a floating Array b=[0.5, 0.671, 0.875, 1.5]. When I try to concatenate with cat(dims=2,a,b), I obtain what I want, but the integer numbers are now floating numbers:

4×2 Array{Float64,2}:
1.0 0.5
2.0 0.671
3.0 0.875
4.0 1.5

How can I obtain the same concatenated Array but with integers in the first column?

Don’t know if this is the best but you could promote one of the arrays to Any

julia> cat(Vector{Any}(a), b; dims=2)
4×2 Array{Any,2}:
 1  0.5
 2  0.671
 3  0.875
 4  1.5
1 Like

Thank you for the quick answer :slight_smile: The concatenated Array is not big, so I Think it can do the trick :slight_smile: I will test if the steps that need that Array aren’t affected!

Comprehensions seem to go by promote_typejoin instead, so you could do this:

julia> [x[i] for i in 1:4, x in (a,b)]
4×2 Array{Real,2}:
 1  0.5
 2  0.671
 3  0.875
 4  1.5
1 Like

Thank you! Both solutions work for me :slight_smile:

You can do

julia> Real[a b]
4×2 Array{Real,2}:
 1  0.5
 2  0.671
 3  0.875
 4  1.5
3 Likes

Another good option :slight_smile:

1 Like