,可以通过以下方式来实现:
def get_2d_index_from_flattened_array(flattened_array, rows, cols, target):
index = flattened_array.index(target)
row_index = index // cols
col_index = index % cols
return (row_index, col_index)
# 示例用法
flattened_array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
rows = 3
cols = 3
target = 5
result = get_2d_index_from_flattened_array(flattened_array, rows, cols, target)
print(result) # 输出结果为 (1, 2),表示目标值在原二维数组中的行列索引为 (1, 2)
以上是一个完善且全面的答案,提供了从平面化数组中获取二维索引的解答步骤和示例代码,并推荐了腾讯云相关产品和产品介绍链接地址。
小程序·云开发官方直播课(数据库方向)
腾讯云 TVP AI 创变研讨会
Elastic 中国开发者大会
TVP分享会
小程序云开发官方直播课(应用开发实战)
腾讯云GAME-TECH沙龙
云+社区技术沙龙[第6期]
云+社区技术沙龙[第10期]
云+社区技术沙龙 [第30期]
腾讯位置服务技术沙龙
领取专属 10元无门槛券
手把手带您无忧上云