我將Matlab中的代碼轉換爲Python。在Matlab中的代碼是:將matlab中的find()轉換爲python
x = find(sEdgepoints > 0 & sNorm < lowT);
sEdgepoints(x)=0;
這兩個陣列的大小相同,我基本上創建一個面具。
我讀here非零()在numpy相當於find(),所以我用它。在Python中,我擁有sEdgepoints的dstc和sNorm的dst。我也直接放在lowT = 60所以,代碼爲
x = np.nonzero(dstc > 0 and dst < 60)
dstc[x] = 0
不過,我得到以下錯誤:
Traceback (most recent call last):
File "C:\Python27\Sheet Counter\customsobel.py", line 32, in <module>
x = np.nonzero(dstc > 0 and dst < 60)
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
我讀到a.any的使用()/年。所有()in this post,我不知道如何工作。所以,我有兩個問題: 1.如果它確實使用哪個數組? 2.如果我是正確的,它不起作用,如何轉換代碼?
這是行得通的,但對不起,我不能贊成,因爲我的聲譽是不夠的。謝謝! – Epsilon7
沒問題 - 我也在那裏。很高興你有一個解決方案! – qbzenker