c++ - How to check for real equality (of numpy arrays) in python? -


i have function in python returning numpy.array:

matrix = np.array([0.,0.,0.,0.,0.,0.,1.,1.,1.,0.],              [0.,0.,0.,1.,1.,0.,0.,1.,0.,0.])  def some_function:     rows1, cols1 = numpy.nonzero(matrix)     cols2 = numpy.array([6,7,8,3,4,7])     rows2 = numpy.array([0,0,0,1,1,1])     print numpy.array_equal(rows1, rows2) # returns true     print numpy.array_equal(cols1, cols2) # returns true     return (rows1, cols1)                   # or (rows2, cols2) 

it should extract indices of nonzero entries of matrix (rows1, cols1). however, can extract indices manually (rows2, cols2). problem program returns different results depending on whether function returns (rows1, cols1) or (rows2, cols2), although arrays should equal.

i should add code used in context of pyipopt, calls c++ software package ipopt. problem occurs within package.

can arrays not "completely" equal? somehow must because not modifying returning 1 instead of other.

any idea on how debug problem?

you check where arrays not equal:

print(where(rows1 != rows2)) 

but doing unclear, first there no nonzeros function in numpy, nonzero returns tuple of coordinates. using 1 corresponding rows?


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -