floating point - Convert float 2-D array to integer 2-D array in Julia -


i know possible convert float64 int64 using convert function. unfortunately, doesn't work when applying convert 2-d array.

julia> convert(int64, 2.0) 2  julia> = [1.0 2.0; 3.0 4.0] 2x2 array{float64,2}:  1.0  2.0  3.0  4.0  julia> convert(int64, a) error: `convert` has no method matching convert(::type{int64}, ::array{float64,2 })  in convert @ base.jl:13 

how convert 2-d array of floats 2-d array of ints?

what tried

i using following code, little verbose works. hoping there easier way though.

julia> = [1.0 2.0; 3.0 4.0] 2x2 array{float64,2}:  1.0  2.0  3.0  4.0  julia> b = array(int64, 2, 2) 2x2 array{int64,2}:  4596199964293150115  4592706631984861405  4604419156384151675                    0  julia> = 1:2            j = 1:2                b[i,j] = convert(int64,a[i,j])            end        end  julia> b 2x2 array{int64,2}:  1  2  3  4 

an answer doesn't work me

               _    _       _ _(_)_     |  fresh approach technical computing   (_)     | (_) (_)    |  documentation: http://docs.julialang.org    _ _   _| |_  __ _   |  type "help()" help.   | | | | | | |/ _` |  |   | | |_| | | | (_| |  |  version 0.3.10 (2015-06-24 13:54 utc)  _/ |\__'_|_|_|\__'_|  |  official http://julialang.org release |__/                   |  x86_64-linux-gnu  julia> = [1.2 3.4; 5.6 7.8] 2x2 array{float64,2}:  1.2  3.4  5.6  7.8  julia> round(int64, a) error: `round` has no method matching round(::type{int64}, ::array{float64,2}) 

use int function:

julia> = rand(2,2) 2x2 array{float64,2}: 0.145651  0.362497 0.879268  0.753001  julia> int(a) 2x2 array{int64,2}: 0  0 1  1 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -