np.index在numpy中的julia等价物是什么?

np.index在numpy中的julia等价物是什么?,julia,Julia,在Python中,有,它返回网格的索引: Python 2.7.1 > import numpy as np > x,y = np.indices((2,2)) > x array([[0, 0], [1, 1]]) > y array([[0, 1], [0, 1]]) 朱莉娅的类似功能是什么?特别是多维网格 我尝试了eachindex,但它需要一个网格作为输入,而不仅仅是维度。此外,输出是线性索引的平面列表,而不是单独的笛卡尔分量。可以使

在Python中,有,它返回网格的索引:

Python 2.7.1
> import numpy as np
> x,y = np.indices((2,2))
> x
array([[0, 0],
       [1, 1]])
> y
array([[0, 1],
       [0, 1]])
朱莉娅的类似功能是什么?特别是多维网格


我尝试了
eachindex
,但它需要一个网格作为输入,而不仅仅是维度。此外,输出是线性索引的平面列表,而不是单独的笛卡尔分量。

可以使用
笛卡尔细分功能获得:

julia> inds = CartesianIndices((2,2))
2×2 CartesianIndices{2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}:
 CartesianIndex(1, 1)  CartesianIndex(1, 2)
 CartesianIndex(2, 1)  CartesianIndex(2, 2)

julia> Tuple.(inds)
2×2 Array{Tuple{Int64,Int64},2}:
 (1, 1)  (1, 2)
 (2, 1)  (2, 2)

julia> getindex.(inds, 1)
2×2 Array{Int64,2}:
 1  1
 2  2

julia> getindex.(inds, 2)
2×2 Array{Int64,2}:
 1  2
 1  2

另请注意,您可以使用上述
inds
数组的条目直接为给定维度的数组编制索引。如果您更喜欢线性索引而不是笛卡尔索引,则可以使用
LinearIndices
函数。