【问题标题】:TypeError: int() argument must be a string, a bytes-like object or a number, not 'map'TypeError: int() 参数必须是字符串、类似字节的对象或数字,而不是“映射”
【发布时间】:2021-01-14 13:08:12
【问题描述】:

我无法运行此代码,并且出现以下错误:

strucArray = np.array(arrayTuple, np.dtype([('inSeqNum', np.int), (lstVals[0], np.float)]))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'map'

这是代码块:

seqnum = None
lstFile = open(inListFileName)

for lstLn in lstFile.readlines():
    lstVals = lstLn.strip().split()

    basePath=os.getcwd()
    file=os.path.join(basePath, 'OUT_ST',lstVals[1])

    if len(lstVals) > 1:
        loadArray = np.loadtxt(file).flatten()

        if seqnum is None:
            seqnum = np.arange(1, len(loadArray) + 1)
    
        arrayTuple = map(tuple, np.column_stack((seqnum, loadArray)))
        
        strucArray = np.array(arrayTuple, np.dtype([('inSeqNum', np.int), (lstVals[0], np.float)]))
    
        arcpy.da.ExtendTable(target, seqFieldName, strucArray, 'inSeqNum', False)

lstFile.close()

【问题讨论】:

  • 在 Python3 中 map 不计算其值;它只是设置了一个映射。实际执行映射需要list(map...)。

标签: arrays python-3.x numpy dictionary arcpy


【解决方案1】:

我认为你只需要在这一行添加一个列表转换:

strucArray = np.array(arrayTuple, np.dtype([('inSeqNum', np.int), (lstVals[0], np.float)])

到这里:

strucArray = np.array(list(arrayTuple), np.dtype([('inSeqNum', np.int)`, (lstVals[0], np.float)]))

【讨论】:

    猜你喜欢
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多