我有一個需要比較兩個陣列的斷言。我試過assert arrayOne == arrayTwo is True了,但它回傳了Assertion error。
然后我嘗試np.testing.assert_allclose(str(arrayTwo), str(arrayOne))了但我仍然收到此錯誤:
TypeError: The DType <class 'numpy._FloatAbstractDType'> could not be promoted by <class 'numpy.dtype[str_]'>. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is `object`. The full list of DTypes is: (<class 'numpy.dtype[str_]'>, <class 'numpy._FloatAbstractDType'>)
它說它具有不同的資料型別,但我繼續強制將其轉換為字串,但沒有發生任何事情。我應該怎么辦?這是我的代碼:
對于arrayOne:
something = context.pageobject.method()
for div in something:
global arrayOne
index = 1 something.index(div)
finalSomething = str(index) ' - ' div.text
arrayOne.append(str(finalSomething))
print(arrayOne)
對于arrayTwo:
excelTitle = download_path "/" context.pageobject.anotherLocator().text.strip()
excelWorkbook = o.load_workbook(excelTitle)
sheetNames = excelWorkbook.sheetnames
arrayTwo = str(sheetNames)
print("The sheetnames are: " arrayTwo)
uj5u.com熱心網友回復:
嘗試
numpy.array_equal(a1, a2, equal_nan=False)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/506707.html
下一篇:從Booking.com抓取資訊
