Hi,

programista...@gmail.com 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