Ask Your Question
0

How to transmit a parameter to a function called in an other function?

asked 2020-08-06 18:57:19 +0200

Cyrille gravatar image

updated 2020-08-07 12:19:54 +0200

slelievre gravatar image

Here are 2 functions: the second one calls the first one but obviously it doesn't transmit the value of sw to the first and I have an error of execution. So how should I do to obtain that sw be transmitted to pos_rat(x, y, sw) by ratio_for_pivot(x, y, sw)?

 def pos_rat(x, y, sw):
    if y > 0:
        return x/y
    else:
        if sw == 1:
            return "-"
        elif sw == 2:
            return -100000

def ratio_for_pivot(mat, var_ent, sw):
    return [pos_rat(mat[i][mat.ncols() - 1], mat[i][var_ent], sw)
            for i in range(mat.nrows() - 1)]
edit retag flag offensive close merge delete

Comments

Ideally, provide a minimal example of calling the functions to illustrate the question.

slelievre gravatar imageslelievre ( 2020-08-07 12:23:14 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-08-06 22:32:19 +0200

Cyrille gravatar image

updated 2020-08-07 12:19:39 +0200

slelievre gravatar image

I know this is more a Python question. Here is my answer:

def pos_rat(x, y, sw):
    if y > 0:
        return x/y
    else:
        if sw == 1:
            return "-"
        elif sw == 2:
            return -100000

def ratio_for_pivot(mat, var_ent, sw):
    a = [pos_rat(mat[i][mat.ncols() - 1], mat[i][var_ent], sw)
         for i in range(mat.nrows() - 1)]
    return a
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-08-06 18:57:19 +0200

Seen: 64 times

Last updated: Aug 07 '20