英文:
CartesianIndices from start and end tuples
问题
我想使用起始和结束元组构建CartesianIndices
。例如,我想使用start = (2,3)
和end = (4,5)
构建CartesianIndices((2:4, 3:5))
。
CartesianIndices
没有为此提供构造函数。是否有简单的替代方法?
英文:
I want to construct CartesianIndices
using start and end tuples. For example, I want to construct CartesianIndices((2:4, 3:5))
given start = (2,3)
and end = (4,5)
.
CartesianIndices
provides no constructor for this. Is there an easy alternative?
答案1
得分: 1
是的,有的:
julia> CartesianIndices(UnitRange.((2,3), (4,5))) |> collect
3×3 Matrix{CartesianIndex{2}}:
CartesianIndex(2, 3) CartesianIndex(2, 4) CartesianIndex(2, 5)
CartesianIndex(3, 3) CartesianIndex(3, 4) CartesianIndex(3, 5)
CartesianIndex(4, 3) CartesianIndex(4, 4) CartesianIndex(4, 5)
英文:
Yes, there is:
julia> CartesianIndices(UnitRange.((2,3), (4,5))) |> collect
3×3 Matrix{CartesianIndex{2}}:
CartesianIndex(2, 3) CartesianIndex(2, 4) CartesianIndex(2, 5)
CartesianIndex(3, 3) CartesianIndex(3, 4) CartesianIndex(3, 5)
CartesianIndex(4, 3) CartesianIndex(4, 4) CartesianIndex(4, 5)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论