[Python] A weird warning appears in np.where() [duplicate]

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    This code gives me a warning:

    a = np.array([
    [0, 1, 2],
    [3, 0, 4],
    [5, 6, 0]
    ])

    print(np.where(a > 2.2, np.log(4 * a), 0))


    The warning message is RuntimeWarning: divide by zero encountered in log print(np.where(a > 2.2, np.log(4 * a), 0)).

    The warning would be obvious if I did np.log(0) straight forward, but here I am using np.where so I expect it to skip all 0 elements by skipping all the elements less or equal to 2.2.

    N.B. I know how to avoid warning messages to appear in stdout so there is no problems with it. I just worder if np.where works the way I dont expect it to work.

    Continue reading...

Compartilhe esta Página