Search code examples
pythonarraysnew-operator

What is TypeError: 'type' object is not subscriptable?


for j in range(640):
        for i in range(400):
            # nimg[j][i] = resam(img, x, y)
            K2 = K/2
            sum = 0.0
            a = -K2
            for s in range[a,K2+1, 1]:
                for t in range[a,K2+1, 1]:
                    sum += resam(img,x+(K2*d), y+(K2*d))
                    nimg[j][i] = int(sum/(K*K))

Error:

Traceback (most recent call last):
  File "PyIP2.py", line 56, in <module>
    resize(img,nimg)
  File "PyIP2.py", line 29, in resize
    for s in range[a,K2, 1]:
TypeError: 'type' object is not subscriptable

What is the solution for same as i am not able to understand?


Solution

  • The mistake you did was to use [](square brackets) instead of ()(curve brackets)

    The fix is simple:

    for j in range(640):
        for i in range(400):
            # nimg[j][i] = resam(img, x, y)
            K2 = K/2
            sum = 0.0
            a = -K2
            for s in range(a,K2+1, 1):
                for t in range(a,K2+1, 1):
                    sum += resam(img,x+(K2*d), y+(K2*d))
                    nimg[j][i] = int(sum/(K*K))