0

I,m trying to calculate the shortest distance between a collection of points and a line segment. Everything goes well untill it has to calculate the distance using values from two sets of arrays one for the x distances and one for the y distances.

The line for calculating the distance is:

d = np.sqrt( dx**2 + dy**2 ).

It tells me that::

ValueError: operands could not be broadcast together with shapes (3312,) (0,) 

I've used the script before with another set of values and it works perfectly. But now it does not any more. And I tried tot find the meaning of the error message but have not been successful so far. Can someone help?

Anti
  • 41
  • 1
  • 6
  • possible duplicate of [Numpy Operands could not be broadcast together with shape](http://stackoverflow.com/questions/11856493/numpy-operands-could-not-be-broadcast-together-with-shape) – Azd325 Apr 06 '15 at 08:29

2 Answers2

5

ValueError Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value

Demo:

>>> int("1")
1
>>> int("h")         # valueError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'h'
Hackaholic
  • 19,069
  • 5
  • 54
  • 72
2

Your problem seems to be, that dx and dy are two arrays of different length, dx has a length of 3312, and dy a length of 0. Better check if dy is correctly set.

If i reproduce your problem with two arrays of length 6 and 0 I get the same error, if I use two arrays of the same length it works just fine.

max
  • 46
  • 3