[Python] numpy.hstack gives: TypeError: _vhstack_dispatcher() takes 1 positional argument but...

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I have this python code that takes in Nx2 numpy array in which each row represents the [x,y] coordinates of one of the N points, and it returns an array of the same size containing transformed [u,v] coordinates for each point.

    def inverse(arr):
    return np.hstack([arr[:, 0:1], arr[:, 1:2] - arr[:, 0:1]**2])


    The transformation is defined as

    u = x
    v = y - x^2


    This code works fine. But then I have the transformation

    u = sqrt(x^2 + y^2)
    v = arctan2(y, x)


    And the code is

    def inverse(arr):
    return np.hstack(np.sqrt(arr[:, 0:1]**2 + arr[:, 1:2]**2), np.arctan2(arr[:, 1:2], arr[:, 0:1]))


    But this code gives the following error:

    TypeError: _vhstack_dispatcher() takes 1 positional argument but 2 were given


    What could be the reason for this? How can I fix this?

    Continue reading...

Compartilhe esta Página