Home > OS >  Python Numpy: How can we compare arrays?
Python Numpy: How can we compare arrays?

Time:09-13

I have an assertion that needs to compare two arrays. I have tried assert arrayOne == arrayTwo is True but it returns Assertion error.

Then I tried np.testing.assert_allclose(str(arrayTwo), str(arrayOne)) But I'm still getting this error:

 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'>)

It says that it has different data types but I keep on forcing to convert it to string but nothing is happening. What should I do? Here is my code:

For 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)

For 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)

CodePudding user response:

Try

numpy.array_equal(a1, a2, equal_nan=False)
  • Related