gpt4 book ai didi

python - 将 1x336 数组转换为 16x21 数组

转载 作者:太空宇宙 更新时间:2023-11-03 18:27:04 24 4
gpt4 key购买 nike

我正在尝试创建一个 1x336 列数组,并用 336 个要素类的属性表中的数据填充它。我想我已经成功完成了这个任务。接下来,我想将这个1x336数组重新排列成16x21数组,并将其保存为txt文件。

任何帮助将不胜感激。

import arcpy
from arcpy import env
import numpy

arcpy.env.workspace="C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Minimize_DEM_Analysis\PolyConvert\out_prj.gdb"
arcpy.env.overwriteOutput=True


filename="C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Minimize_DEM_Analysis\PolyConvert\areatable.txt"

fcs=arcpy.ListFeatureClasses("*")
areafield="Area_km"

n=16
areaColumn=[]
arealist=numpy.zeros([16,21],dtype=numpy.float64)
areaset=set()
print arealist

for fc in fcs:
print fc
rows = arcpy.SearchCursor(fc)
for row in rows:
area=row.getValue(areafield)
print area
print 'appending area'
if area not in areaset:
areaColumn.append(area)
print'adding area'
areaset.add(area)
print areaColumn

for i in range(n):
for j in range(0,21):
arealist[i,j]=areaColumn[:] #This is where I have been trying to call each row from areaColumn
print arealist

我也尝试过 reshape 功能,但没有成功:

finalarea=arealist.reshape(arealist.size//16,21)
print finalarea

最佳答案

您应该知道 reshape 采用元组作为参数。以下内容应该有效:

finalarea = arealist.reshape((16,21))

关于python - 将 1x336 数组转换为 16x21 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22976322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com