BIG THX, but what about Float array ?
julia> Int.(rand(Bool,10))
10-element Array{Int64,1}:
 1
 0
 1
 1
 1
 0
 1
 0
 0
 0

julia> Int.(rand(10))
ERROR: InexactError()
 in macro expansion at .\broadcast.jl:129 [inlined]
 in macro expansion at .\simdloop.jl:73 [inlined]
 in macro expansion at .\broadcast.jl:123 [inlined]
 in _broadcast!(::Type{Int64}, ::Array{Int64,1}, ::Tuple{Tuple{Bool}}, 
::Tuple{Tuple{Int64}}, ::Tuple
 ::Type{Val{1}}) at .\broadcast.jl:117
 in broadcast!(::Type{T}, ::Array{Int64,1}, ::Array{Float64,1}) at 
.\broadcast.jl:172
 in broadcast_t(::Type{T}, ::Type{T}, ::Array{Float64,1}, 
::Vararg{Array{Float64,1},N}) at .\broadcas
 in broadcast(::Type{T}, ::Array{Float64,1}) at .\broadcast.jl:230

W dniu czwartek, 27 października 2016 10:00:42 UTC+2 użytkownik Ángel de 
Vicente napisał:
>
> Hi, 
>
> program...@gmail.com <javascript:> writes: 
>
> > in ver 0.5 how to convert to Int f.e bool or Float 
> > 
> > julia> int(rand(Bool,10)) 
> > ERROR: UndefVarError: int not defined 
> > 
> > julia> convert(Int64,rand(Bool,10)) 
> > ERROR: MethodError: Cannot `convert` an object of type Array{Bool,1} to 
> an 
> > object of type Int64 
> > This may have arisen from a call to the constructor Int64(...), 
> > since type constructors fall back to convert methods. 
> > 
>
> just learning Julia, so probably there are better ways, but this works: 
>
> ,---- 
> | julia> VERSION 
> | v"0.5.0" 
> | 
> | julia> Int(rand(Bool)) 
> | 1 
> | 
> | julia> [Int(x) for x in rand(Bool,5)] 
> | 5-element Array{Int64,1}: 
> |  0 
> |  1 
> |  0 
> |  1 
> |  0 
> | 
> | julia> 
> `---- 
>
> -- 
> Ángel de Vicente 
> http://www.iac.es/galeria/angelv/           
>

Reply via email to