朱莉娅 |带有示例的 checkbounds()函数
checkbounds()
是 julia 中的一个内置函数,如果给定的索引值在给定数组的范围内,则用于返回 true,否则返回 false。
Syntax: checkbounds(Bool, Array, Index)
Parameters: This function accepts three parameters which are illustrated below:-
- Bool: This says that this function will return boolean values as output.
- Array: It is the given array with bounds
- Index: It is the index value which is going to be calculated either it lies in the array bounds or not.
Returns: It returns the value true if the index value lies in the array bounds else false.
以下是一些说明上述函数的代码:
示例 #1:
# Julia Program for illustration of
# checkbounds() function
# Initializing an array from 1 to 10
A = rand(1, 10);
# Initializing a index value of 5
Index = 5
# Calling the checkbounds() function
A = checkbounds(Bool, A, Index)
# Getting the value true or false
println(A)
输出:
true
示例 #2:
# Julia Program for illustration of
# checkbounds() function
# Initializing a range from 1 to 10
A = rand(1, 10);
# Initializing a index value of 15
Index = 15
# Calling the checkbounds() function
A = checkbounds(Bool, A, Index)
# Getting the value true or false
println(A)
输出:
false