view()
是 julia 中的一个内置函数,用于将视图返回到具有给定索引的给定父数组 A 中,而不是制作副本。
Syntax: view(A, inds…)
Parameters:
- A: Specified parent array.
- inds: Specified indices.
Returns: It returns a view into the given parent array A with the given indices instead of making a copy.
例子:
# Julia program to illustrate
# the use of view() method
# Getting a view into the given parent
# array A with the given indices
# instead of making a copy.
A = [5, 10, 15, 20];
println(view(A, 2))
B = [5 10; 15 20];
println(view(B, :, 1))
C = cat([1 2; 3 4], [5 6; 7 8], dims = 3);
println(view(C, :, :, 1))
输出:
@看法()
@view()
是 julia 中的一个内置函数,用于从给定的索引表达式创建一个子数组。
Syntax:
@view A[inds…]
Parameters:
- A: Specified parent array.
- inds: Specified indices.
Returns: It returns the created sub array from the given indexing expression.
例子:
# Julia program to illustrate
# the use of @view() method
# Getting the created sub array
# from the given indexing expression.
A = [5, 10, 15, 20];
println(@view A[3])
B = [5 10; 15 20];
println(@view B[:, 1])
C = cat([1 2; 3 4], [5 6; 7 8], [2 2; 3 4], dims = 3);
println(@view(C[:, :, 2]))
输出:
@视图()
@views()
是 julia 中的一个内置函数,用于转换给定表达式中的每个给定数组切片操作。
Syntax:
@views expression
Parameters:
- expression: Specified expression.
Returns: It returns the desired view.
例子:
# Julia program to illustrate
# the use of @views() method
# Getting the created sub array
# from the given indexing expression.
A = zeros(4, 4);
@views for row in 2:4
b = A[row, :]
b[:] .= row
end
println(A)
输出: