我正在使用python,我是新的。我想從我的代碼繪製兩個數組,其中之一是情節正確,但對方一引發我一個錯誤:在python上繪製數組時出錯
/usr/lib64/python2.7/site-packages/matplotlib/axes.py:4511: RuntimeWarning: invalid value encountered in true_divide
c /= np.sqrt(np.dot(x, x) * np.dot(y, y))
Traceback (most recent call last):
File "./track-multiple.py", line 169, in <module>
ax2.xcorr(x2, y2)
File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 4508, in xcorr
c = np.correlate(x, y, mode=2)
File "/usr/lib64/python2.7/site-packages/numpy/core/numeric.py", line 871, in correlate
return multiarray.correlate2(a, v, mode)
ValueError: object too deep for desired array
的代碼是下一個:
x1 = np.arange(0,len(colunas[0],1)
y1 = columnas[0]
x2 = np.arange(0,len(filas))
y2 = filas
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax1.xcorr(x1,y1)
ax1.axhline(0, color='black', lw=2)
ax2 = fig.add_subplot(212, sharex=ax1)
ax2.xcorr(x2,y2)
ax2.axhline(0, color='blue', lw=2)
plt.show()
我認爲這個問題是由於他的維度而導致的,或者我濫用了xcorr方法。如果我做一個打印上filas和columnas我得到這個:
filas =
[[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
...
[0]
[0]
[0]
[0]
[0]]
columnas =
[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0]]
兩個陣列用OpenCV的庫中創建這些句子:
columnas = cv2.reduce(fgmask,0,cv.CV_REDUCE_MAX)
filas = cv2.reduce(fgmask,1,cv.CV_REDUCE_MAX)
等待的想法!
PD:OK,我覺得如何修正這個錯誤,我只是轉換陣列filas有:
filas = filas[:,0]
但我不知道錯誤的確切原因,以及修復,任何人都可以回答我的問題?
我忘了謝謝你,對我有用:D – 2015-04-16 21:33:24