I’m not aware of an equivalent to that function, but it doesn’t seem too hard to implement. (And since this is Julia, our implementations can be as fast as ones from libraries.)
julia> x = 0:5
0:5
julia> condmat = [x .< 3 x .> 3]
6Ă—2 BitMatrix:
1 0
1 0
1 0
0 0
0 1
0 1
julia> choicemat = [x x.^2]
6Ă—2 Matrix{Int64}:
0 0
1 1
2 4
3 9
4 16
5 25
julia> function conditionalselect(conditionmatrix, choicematrix, default = zero(eltype(choicematrix)))
@assert size(conditionmatrix) == size(choicematrix)
result = fill(default, size(choicematrix, 1))
for (rownum, conditionrow) in pairs(eachrow(conditionmatrix))
choice = findfirst(conditionrow)
if !isnothing(choice)
result[rownum] = choicematrix[rownum, choice]
end
end
result
end
conditionalselect (generic function with 1 method)
julia> conditionalselect(condmat, choicemat, 42)
6-element Vector{Int64}:
0
1
2
42
16
25
Although it’s possible to implement a select function in Julia, I would re-think your whole approach. For both performance and clarity you really want to do this sort of thing in a single loop or comprehension as demonstrated by @Danabove.
The Matlab or Numpy style of doing a sequence of “vectorized” calls leaves a lot of performance on the table because it constructs a sequence of temporary arrays just to discard them at the end. It’s also, in my opinion, a lot clearer to write a single loop in many cases.
Loops are fast in Julia; you don’t need to fear them like you would in Python. Programming doesn’t have to be an exercise in “mining” the standard library and hoping you can find just the function that you need.