2015-04-06 39 views
1

我試圖計算一組點和線段之間的最短距離。一切都很順利,直到它使用兩組數組中的值來計算距離,一組用於x距離,另一組用於y距離。ValueError是什麼意思?

計算距離的線路是:

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

它告訴我說::

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

我以前使用的腳本與另一組值和它完美的作品。但現在它不再有了。我試圖找出錯誤信息的含義,但迄今爲止尚未成功。有人可以幫忙嗎?

+0

可能重複的能不能與形狀一起播出](http://stackoverflow.com/questions/11856493/numpy-operands-could-not-be-broadcast-together-with-shape) – Azd325 2015-04-06 08:29:08

回答

2

你的問題似乎是,dx和dy是兩個不同長度的數組,dx的長度爲3312,dy的長度爲0. 更好地檢查dy是否被正確設置。

如果我重現您的問題與長度6和0兩個數組我得到同樣的錯誤,如果我使用兩個相同長度的數組,它工作得很好。

+0

非常感謝你的幫助。 – Anti 2015-04-06 09:01:29

3

ValueError異常 時引發一個內置的操作或功能的接收,其具有合適的類型,但不合適的值的參數

演示:

>>> 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' 
[numpy的操作數的