Home:ALL Converter>Filter array of arrays in Julia by simple command

Filter array of arrays in Julia by simple command

Ask Time:2018-09-18T02:50:24         Author:Lem Lam

Json Formatter

I have an array of two arrays like this

x = [[1.5, 2.5], [3.5, 4.5]]

where the two inner arrays always have equal length.

I want to apply a filter in a pairwise manner. The pairs in the above example would be [1.5, 3.5] and [2.5, 4.5]. The filter criterium should be to select a pair if both elements are larger than a critical value, say 2. The result should be again in the original form, i.e.

result = [[2.5],[4.5]]

Another example would be

x = [[1.5, 2.5, 3.5], [4.5, 5.5, 6.5]] -> result = [[2.5, 3.5], [5.5, 6.5]].

How can I achieve this?

Author:Lem Lam,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52374069/filter-array-of-arrays-in-julia-by-simple-command
carstenbauer :

Sort of guessing your precise filter criterium, one option would be\n\njulia> using SplitApplyCombine\n\njulia> x = [[1.5, 2.5, 3.5], [4.5, 5.5, 6.5]];\n\njulia> invert(filter(y->y[1]>2&&y[2]>2, invert(x)))\n2-element Array{Array{Float64,1},1}:\n [2.5, 3.5]\n [5.5, 6.5]\n\n\nNot that the method invert is defined in the external package SplitApplyCombine.jl which you have to add first (] add SplitApplyCombine).\n\nHowever, a straight forward for-loop implementation would work as well and would probably be faster.",
2018-09-17T19:35:46
张实唯 :

To keep any but the first element\n\njulia> x = [[1.5, 2.5, 3.5], [4.5, 5.5, 6.5]];\n\njulia> (x->x[2:end]).(x)\n2-element Array{Array{Float64,1},1}:\n [2.5, 3.5]\n [5.5, 6.5]\n",
2018-09-18T01:28:30
yy