這個findnext()
是 julia 中的一個內置函數,用於返回指定數組 A 的真元素的 i 之後或包括 i 的下一個索引,或者如果沒有找到真值則返回零。這裏索引或鍵的值從 1 開始,即第一個元素的索引為 1,第二個元素的索引為 2,依此類推。
用法:
findnext(A, i)
or
findnext(predicate::Function, A, i)
參數:
- A:指定數組
- i:指定值
- Predicate Function:根據指定的參數確定某事是真還是假
返回值:它返回指定數組 A 的真元素之後或包含 i 的下一個索引,如果沒有找到真值,則返回零。
範例1:
# Julia program to illustrate
# the use of Array findnext() method
# Finding index of next true value coming
# after or including index 1 from
# the 1D array A
A = [false, true, true, false]
println(findnext(A, 1))
# Finding index of next true value coming
# after or including index (1, 1) from
# the 2D array B of size 2 * 2
B = [false false; true false]
println(findnext(B, CartesianIndex(1, 1)))
# Finding index of next true value coming
# after or including index (1, 2, 1) from
# the 3D array C of size 2 * 2*2
C = cat([false false; true false],
[false true; true false],
[true false; true true], dims = 3)
println(findnext(C, CartesianIndex(1, 2, 1)))
輸出:
範例2:
# Julia program to illustrate
# the use of Array findnext() method
# Finding index of next even value coming
# after or including index 1 from
# the 1D array A
A = [1, 2, 5, 6]
println(findnext(iseven, A, 1))
# Finding index of next even value coming
# after or including index (1, 1) from
# the 2D array B of size 2 * 2
B = [3 5; 6 7]
println(findnext(iseven, B, CartesianIndex(1, 1)))
# Finding index of next even value coming
# after or including index (1, 2, 1) from
# the 3D array C of size 2 * 2*2
C = cat([1 2; 3 4], [5 6; 7 8],
[9 10; 11 12], dims = 3)
println(findnext(iseven, C, CartesianIndex(1, 2, 1)))
輸出:
相關用法
- Julia findnext()用法及代碼示例
- Julia Array findprev()用法及代碼示例
- Julia Array findfirst()用法及代碼示例
- Julia Array findlast()用法及代碼示例
- Julia Array findall()用法及代碼示例
- Julia isassigned()用法及代碼示例
- Julia setindex!()用法及代碼示例
- Julia eachindex()用法及代碼示例
- Julia findmax()用法及代碼示例
- Julia findmin()用法及代碼示例
- Julia getindex()用法及代碼示例
- Julia ndims()用法及代碼示例
- Julia length()用法及代碼示例
- Julia size()用法及代碼示例
- Julia sizeof()用法及代碼示例
- Julia findlast()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Get next true value from a given array index in Julia | Array findnext() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。