How to convert Any '5' to Int 5?


#1

how to convert Any ‘5’ to Int 5 ?
now ‘5’ is converted to 53
julia> test
11449238-element Array{Any,1}:
‘5’
‘1’
‘1’
‘1’
‘1’
‘1’
‘2’
‘2’

julia> convert(Array{Int64},test)
11449238-element Array{Int64,1}:
53
49
49
49
49
49
50
Paul


#2

What you are doing is not convertion but parsing so, parse.(Int, test).

Although actually since you have character instead of string you’ll need test .- '0'


#3

Thianks. Nice in Julia 6 .0 but im using 5.0 …

parse.(Int64, test)
ERROR: MethodError: no method matching size(::Type{Int64})
Closest candidates are:
size{N}(::Any, ::Integer, ::Integer, ::Integer…) at abstractarray.jl:48
size(::BitArray{1}) at bitarray.jl:39
size(::BitArray{1}, ::Any) at bitarray.jl:43

in broadcast_shape(::Type{T}, ::Array{Any,1}) at .\broadcast.jl:31
in broadcast_t(::Function, ::Type{Any}, ::Type{T}, ::Vararg{Any,N}) at
.\broadcast.jl:213
in broadcast(::Function, ::Type{T}, ::Array{Any,1}) at .\broadcast.jl:230

Paul

W dniu 2017-10-19 o 18:08, Yichao Yu pisze:


#4

Use an array comprehension instead of the broadcast?


#5

Some ide for Juloa 5.0 ?
Paul


#6

plese show me :slight_smile:


#7

[parse(Int,x) for x in test]