Skip to content

Empty slicing behaviour before and after ak.to_numpy is different #1047

Answered by jpivarski
pfackeldey asked this question in Q&A
Discussion options

You must be logged in to vote

It's because ak.Array([[1], [2]]) is an array of variable-length lists and np.array([[1], [2]]) is an array of fixed-length lists:

>>> ak.Array([[1], [2]])                   # note the "var"
<Array [[1], [2]] type='2 * var * int64'>
>>> 
>>> ak.Array(np.array([[1], [2]]))         # now it's regular
<Array [[1], [2]] type='2 * 1 * int64'>

The empty slice maintains var on the var-type array and the regular length of the regular array:

>>> ak.Array([[1], [2]])[[]]
<Array [] type='0 * var * int64'>
>>> 
>>> ak.Array(np.array([[1], [2]]))[[]]
<Array [] type='0 * 1 * int64'>

And this is preserved when converting to NumPy. Var-type arrays can only be converted to NumPy if they happen to be regul…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@pfackeldey
Comment options

pfackeldey Aug 6, 2021
Maintainer Author

@jpivarski
Comment options

@jpivarski
Comment options

Answer selected by pfackeldey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1046 on August 04, 2021 13:39.