Understanding result of array_equal with nested arrays #3418
-
Hi awkward. Thanks for this great codebase, and I'm sorry if I'm asking a question which has been answered elsewhere. I looked around and couldn't find anything. Do you understand why a = ak.Array([
[ [], [1] ],
[ [], [0] ]
])
b = ak.Array([
[ [], [1], [] ],
[ [0] ]
])
print(ak.array_equal(a, b))
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Hi @alexandertuna . Thanks for brining it up. We try to follow the Numpy behaviour in what the functions do. However, it may not always be possible given that we deal with the rugged structures. For example, https://numpy.org/doc/stable/reference/generated/numpy.equal.html#numpy.equal: >>> a = np.array([2, 4, 6])
>>> b = np.array([2, 4, 2])
>>> a == b
array([ True, True, False])
>>> a = np.array([[2, 4, 6], [2, 4, 6]])
>>> b = np.array([[2, 4, 2], [2, 4, 2]])
>>> a == b
array([[ True, True, False],
[ True, True, False]]) If we do the same
So we have to remove the structure: >>> ak.flatten(b)==ak.flatten(a)
<Array [[True], [True], [True], [True]] type='4 * var * bool'> I think, |
Beta Was this translation helpful? Give feedback.
-
The problem is that the two arrays have the same content and different index. That's easy to see if you look at the layouts. In [4]: a = ak.Array([
...: [ [], [1] ],
...: [ [], [0] ]
...: ])
...: b = ak.Array([
...: [ [], [1], [] ],
...: [ [0] ]
...: ])
In [5]: a.layout
Out[5]:
<ListOffsetArray len='2'>
<offsets><Index dtype='int64' len='3'>
[0 2 4]
</Index></offsets>
<content><ListOffsetArray len='4'>
<offsets><Index dtype='int64' len='5'>[0 0 1 1 2]</Index></offsets>
<content><NumpyArray dtype='int64' len='2'>[1 0]</NumpyArray></content>
</ListOffsetArray></content>
</ListOffsetArray>
In [6]: b.layout
Out[6]:
<ListOffsetArray len='2'>
<offsets><Index dtype='int64' len='3'>
[0 3 4]
</Index></offsets>
<content><ListOffsetArray len='4'>
<offsets><Index dtype='int64' len='5'>[0 0 1 1 2]</Index></offsets>
<content><NumpyArray dtype='int64' len='2'>[1 0]</NumpyArray></content>
</ListOffsetArray></content>
</ListOffsetArray>
They both have the same "shape" which is |
Beta Was this translation helpful? Give feedback.
-
@alexandertuna Fixed by #3425. Feel free to close the discussion. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
@alexandertuna Fixed by #3425. Feel free to close the discussion.