TypeError:'map'对象不可订阅(python 3)

时间:2014-10-30 10:23:27

标签: python algorithm python-3.x typeerror

我正在尝试将一个盒子计数算法应用于数据数组,但我似乎无法让它工作。输入数据是ascii文件,其值是元组。所以我将它们全部转换成整数。问题是这个算法只适用于像素,所以我试图把这个算法用于ascii文件。我运行该程序,它运行以下错误:

Traceback (most recent call last):
  File "C:\Users\Joao\Desktop\test.py", line 40, in <module>
    if pixels[bs * bx + kx, bs * by + ky] == theColor:
TypeError: 'map' object is not subscriptable

继承输入文件:

-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999     -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999

这是我的代码:

import numpy as np

import math



im = open('C:/Users/Joao/Desktop/qqqf.txt', 'r')

imgx = 1452
imgy = 1916

array = []
with open("qqqf.txt", "r") as im:
    for line in im:
        array.append(line.split())

np.int32(array)

pixels = map(int, array)

theColor = (0, 0, 0)



# fractal dimension calculation using box-counting method
b = 2 # initial box size in pixels
f = 2 # box scaling factor
n = 3 # number of graph points for simple linear regression
gx = [] # x coordinates of graph points
gy = [] # y coordinates of graph points
for ib in range(n):
    bs = b * f ** ib # box size in pixels
    bnx = int(imgx / bs) # of boxes in x direction of image
    bny = int(imgy / bs) # of boxes in y direction of image
    boxCount = 0
    for by in range(bny):
        for bx in range(bnx):
            # if there are any pixels in the box then increase box count
            foundPixel = False
            for ky in range(bs):
                for kx in range(bs):
                    if pixels[bs * bx + kx, bs * by + ky] == theColor:
                        foundPixel = True
                        boxCount += 1
                        break
                if foundPixel:
                    break
    gx.append(math.log(1.0 / bs))
    gy.append(math.log(boxCount))

我希望你们能帮助我,我是一般的编程新手,我很想让这个工作起来。我认为将ascii转换为光栅图像并从那里进行计算。但我不知道这是否是解决这个问题的最佳方法。

0 个答案:

没有答案