0

I call a function with other function as an argument. The other function return numpy.ndarray.

The code:

class CLASS:
    def method1(self):
        size = 10
        return np.zeros([size,size])
    def method2(self, method):
        res = method()

a = CLASS ()
b = a.method2(a.method1())

The first function throws me TypeError: 'numpy.ndarray' object is not callable

I want to run method2() in the cycle giving different functions as an argument.

QUESTION: Is it any way to run that in Python 3?

1
  • I have trouble understanding your question. Consider reformatting it with an edit. Commented Mar 13, 2019 at 15:05

2 Answers 2

1

It seems like you are passing the result of calling method1 (which is in fact a numpy.ndarray) into method2 rather than the method itself.

The call at the end should be a.method2(a.method1) without the parens.

Sign up to request clarification or add additional context in comments.

Comments

0

The a.method1() returns the result of np.zeros(...) which is a numpy.ndarray

So When you're trying to call method() in method2() it fails because that's not a function.

You probably want this instead:

import numpy as np

class CLASS:
    def method1(self):
        size = 10
        return np.zeros([size,size])
    def method2(self, glcm):
        pass

a = CLASS ()
b = a.method2(a.method1())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.