Ad
TypeError: 'builtin_function_or_method' Object Is Not Subscriptable For Python
I'm writing some code to Medial Axis Transform and got some type error for my array.
import cv2
import numpy as np
img = cv2.imread('cvSmall.png',0)
print(img.shape)
thresh = 230
maxValue = 255
th, dst = cv2.threshold(img, thresh, maxValue, cv2.THRESH_BINARY_INV);
cv2.imshow('image',dst)
fZero = np.zeros((len(dst),len(dst[0])))
for y in range(0,len(dst)-1):
for x in range(0,len(dst[0])-1):
if dst[y][x] == 255:
fZero[y][x] = 1
print(fZero.shape)
global currentF
global nextF
currentF = np.zeros((len(dst),len(dst[0])))
currentF = fZero.copy
nextF = np.zeros((len(dst),len(dst[0])))
def iterationFunction():
for y in range(1,len(dst)-2):
for x in range(1,len(dst[0])-2):
nextF[y][x] += fZero[y][x]
nextF[y][x] += min((currentF[y-1][x]), (currentF[y+1][x]), (currentF[y][x-1]),(currentF[y][x+1]))
#Error in this line
print (nextF)
iterationFunction()
And this is the error I'm getting:
line 37, in iterationFunction nextF[y][x] += min((currentF[y-1][x]), (currentF[y+1][x]), (currentF[y][x-1]),(currentF[y][x+1]))
TypeError: 'builtin_function_or_method' object is not subscriptable
Ad
Answer
This error means you're using []
instead of ()
when calling a function.
In your code currentF = fZero.copy
should be currentF = fZero.copy()
Not doing so makes currentF
a function rather than the result of calling a function. So that produces an error when you try to do currentF[x]
.
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad