Get all array elements with true values in Julia | Array findall() Method
Last Updated :
23 Mar, 2020
The findall()
is an inbuilt function in julia which is used to return a vector of indices or keys of the all true values from the specified array A. If such true values are not present in the array, return an empty array. Here values of index or key start from 1 i.e, for index of 1st element is 1, index of 2nd element is 2 and so on.
Syntax:
findall(A)
or
findall(f::Function, A)
Parameters:
- A: Specified array
- Function: Determines whether something is true or false based on the specified arguments
Returns: It returns a vector of indices or keys of the all true values from the specified array A. If such true values are not present in the array, return an empty array.
Example 1:
A = [false, true, true, false]
println(findall(A))
B = [false false; true false]
println(findall(B))
C = cat([false false; true false],
[false true; true false],
[true false; true true], dims = 3 )
println(findall(C))
|
Output:
Example 2:
A = [ 1 , 2 , 5 , 7 ]
println(findall(iseven, A))
B = [ 3 5 ; 6 7 ]
println(findall(isodd, B))
C = cat([ 6 2 ; 6 4 ], [ 5 6 ; 2 8 ],
[ 2 10 ; 11 1 ], dims = 3 )
println(findall(isodd, C))
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...