You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将网格非矩形区域的索引集合转换为行列取值定义?

问题:从网格索引集生成行列条件表达式

我使用的3×3网格索引定义如下:

|0||1||2|
|3||4||5|
|6||7||8|

我的目标是通过**行列(即x、y值)**来定义区域。比如区域定义为 R = [0, 1, 4],表示包含索引0、1、4的网格单元,期望得到的数学表达式为:

i ∈ R: { (col_i ∈ [0, 1] ∧ row_i = 0) ∨(col_i = 1 and row_i = 0)}

但我不知道如何实现这个转换,目前仅能通过以下代码判断该区域不是矩形:

region_indices=[0, 1, 4]
grid_size=3 #3 col x 3 row
rows=[]
cols=[]
for i in range(len(region_indices)):         
        row=i // grid_size
        col= i % grid_size
        rows.append(row)
        cols.append(col)

max_col=max(cols)
max_row=max(rows)
min_col=min(cols)
min_row=min(rows)

for row in range(min_row, max_row):
    for col in range(min_col, max_col):
           square_index=row*grid_size+col            
           if square_index in region_indices==False:
              isnt_rectangle=True

希望有人能帮我解决这个问题,哪怕不是完整答案也可以,提前感谢!

内容的提问来源于stack exchange,提问作者Beatriz Santos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 19:53:12