OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

numpy.hstack gives: TypeError: _vhstack_dispatcher() takes 1 positional argument but 2 were given

  • Thread starter Thread starter Programmer
  • Start date Start date
P

Programmer

Guest
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.

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

The transformation is defined as

Code:
u = x
v = y - x^2

This code works fine. But then I have the transformation

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

And the code is

Code:
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:

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

What could be the reason for this? How can I fix this?
<p>I have this python code that takes in <code>Nx2</code> numpy array in which each row represents the <code>[x,y]</code> coordinates of one of the N points, and it returns an array of the same size containing transformed <code>[u,v]</code> coordinates for each point.</p>
<pre><code>def inverse(arr):
return np.hstack([arr[:, 0:1], arr[:, 1:2] - arr[:, 0:1]**2])
</code></pre>
<p>The transformation is defined as</p>
<pre><code>u = x
v = y - x^2
</code></pre>
<p>This code works fine. But then I have the transformation</p>
<pre><code>u = sqrt(x^2 + y^2)
v = arctan2(y, x)
</code></pre>
<p>And the code is</p>
<pre><code>def inverse(arr):
return np.hstack(np.sqrt(arr[:, 0:1]**2 + arr[:, 1:2]**2), np.arctan2(arr[:, 1:2], arr[:, 0:1]))
</code></pre>
<p>But this code gives the following error:</p>
<pre><code>TypeError: _vhstack_dispatcher() takes 1 positional argument but 2 were given
</code></pre>
<p>What could be the reason for this? How can I fix this?</p>
 

Latest posts

Top