brohjoe
brohjoe

Reputation: 932

Comparing elements in two numpy arrays results in a memory address

I'm comparing the individual elements in two numpy arrays. The array elements are integers. I'm using the 'equal_arrays' function to do the comparision but it results in giving me the memory address of the result object:

Here is the code:

    act = actual_direction
    pre = predicted_direction
    np.sum(act == pre)
    comparison = act == pre
    equal_arrays = comparison.all
    print(f'equal_arrays : {equal_arrays}\n')

result:

   equal_arrays : <built-in method all of numpy.ndarray object at 0x00000122CA6CA3F0>

Do I have to access the memory address to get the results or is there a more elegant way to get the answer?

Thanks in advance.

Upvotes: 0

Views: 114

Answers (1)

Anonymous
Anonymous

Reputation: 568

Based on what i understand, you need a way to get an array with True or False values, for each corresponding element from the two matrixes, given they have the same shape? (What I am trying to do is get a comparison for each individual element of the arrays.)

If so you can try something to this:

a = np.array([[1,2,3], [4,5,6], [7,8,9]])
b = np.array([[3,2,1], [6,5,4], [9,8,7]])
print(a == b)

Output:

[[False  True False]
 [False  True False]
 [False  True False]]

Upvotes: 2

Related Questions