0

I am trying to index 2D array "matrix" in these two functions. The indexing works well in the "findMin" function, but for the "plotContours" function, I keep getting the following error: "TypeError: 'numpy.float64' object is not callable"

What is the best way to pass a 2D array to a function that also contains integers in the arguments? The 2D array "matrix" is the same variable that I send to both functions.

Here are the two functions:

def findMin(matrix):
    for i in range(len(matrix)):
        for j in range(len(matrix[0])):... 
         [array index processing]
    return xyz

def plotContours(matrix, max, min, range):
    for i in range(len(matrix)):
        for j in range(len(matrix[0])):...
        [array index processing]
    return xyz
7
  • max, min and range are predefined functions in Python, you cannot use them as variables. Commented Sep 23, 2017 at 18:50
  • 1
    @MrGeek, yes you can, but that's exactly why there's a problem here. Commented Sep 23, 2017 at 18:50
  • 1
    @MrGeek: you can, but then you override the builtin. Commented Sep 23, 2017 at 18:51
  • @alexis and WillemVanOnsem thanks for the clarification, but it's still not a good practice, and in this case, range is the problem. Commented Sep 23, 2017 at 18:54
  • Yes, "not good practice" hits the nail on the head. When the builtin is not used it's not obvious why it shouldn't be shadowed (the OP might not even know that min and max are builtins), but this question is a textbook example of why. Commented Sep 23, 2017 at 19:01

1 Answer 1

1

You don't show how you call plotContours(), but since one of its arguments is called range, you don't have access to the Python range() function inside plotContours(): Instead, range is whatever you passed as the fourth argument. You seem to pass a numpy.float64 object, which you then attempt to "call" as if it was a function.

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

1 Comment

Thank you! I did not realize the range call was problematic!

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.