0

I would like to have something like the following function:

calc_map(img_in, img_height, img_width, mapping = np.zeros((image_height, image_width)))
[function body]

apparently it is not possible that the default argument of mapping is depending on other arguments in that function. Is there another way around that without using image_height and image_width as global?

I would imagine to put this in my function:

calc_map(img_in, img_height, img_width)
mapping = np.zeros((image_height, image_width))
[function body]

but I also need to put an already existing mapping into the function and not having overwritten it..

appreciate any help, regards, eli

2 Answers 2

2

Make the default None in the function signature, and then replace it inside the body with whatever you want:

def calc_map(img_in, img_height, img_width, mapping = None)
    if mapping is None:
        mapping = np.zeros((image_height, image_width))
Sign up to request clarification or add additional context in comments.

Comments

0

Make default value to False and check:

def calc_map(img_in, img_height, img_width, mapping = False)
    if not mapping:
        mapping = np.zeros((image_height, image_width))

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.