[Python] Numpy min of a function returns the function it self

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    Okey I don't even know where to ask this or what I am exactly asking, but is basically what the title says: if the argument of numpy.min is a function, it doesn't matter if its defined by the user or not, the output is such function.

    Let me put an example:

    import numpy as np

    def get_third_value(x):
    return x[2]

    xx = np.arange(10)

    print(np.min(get_third_value)) # output: <function the_third at 0x7ffb58c2b240>
    print(np.min(max)) # output: <built-in function max>

    # you can even use them:
    print(np.min(max)(xx)) # output : 9
    print(np.min(get_third_value)(xx)) # output: 2


    Why this happens? Is this the intended behavior? If so, why?

    I have checked other numpy functions and the same happens in some of them

    Continue reading...

Compartilhe esta Página