julia JSON.parse losing type information -


i started learn julia have issue:

i trying use julia's json.parse parse matrix (a list of coordinates) losing type information.

coords = json.parse("[[1.0,-2.0],[3.0,4.0],[5.0,-1.2]]") 

it returning any type instead of float type:

3-element array{any,1}:  {1.0,-2.0}  {3.0,4.0}   {5.0,-1.2} 

how (or convert this) array of floats?

edit. here larger problem:

taxi_df = readtable("./test.csv") coords = [json.parse(x) x in taxi_df[:polyline]] times = [float(length(x)*15) x in coords] df_submission = dataframe() df_submission[:trip_id] = taxi_df[:trip_id] mean_time = mean(times) df_submission[:travel_time] = [max(x, mean_time) x in times] writetable("submission.csv", df_submission) 

i think doing in first place because data list-of-lists in json, can't convert matrix.

you can do

float(hcat(coords...)) 

if columns, or

float(hcat(coords...))' 

if rows. if efficiency critical code, can preallocate output matrix , use loop, e.g.

a = zeros(3,2) in 1:3, j in 1:2   @inbounds a[i,j] = coords[i][j] end 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -