-
Dear experts, Is there any method I can do that? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It becomes an option-type because it might need to insert >>> example = ak.Array([[[{"px": 1, "py": 2, "pz": 3}] * 2]] * 100)
>>> print(example.type)
100 * var * var * {px: int64, py: int64, pz: int64} These lists are already length-2, but the type doesn't say that: the type is "var" (ragged). When you set >>> print(ak.pad_none(example, target=2, clip=2, axis=2).type)
100 * var * 2 * ?{px: int64, py: int64, pz: int64} If you know that all of the lists in a ragged dimension happen to have the same length, you can use ak.to_regular instead of ak.pad_none. >>> print(ak.to_regular(example, axis=2).type)
100 * var * 2 * {px: int64, py: int64, pz: int64} If they aren't all the same length, you can use a slice to ensure that none are longer than 2: >>> print(ak.to_regular(example[:, :, 0:2], axis=2).type)
100 * var * 2 * {px: int64, py: int64, pz: int64} But if any are shorter than 2, you have to fill them with something. ak.pad_none is the only padding function, and it pads them with >>> print(ak.fill_none(ak.pad_none(example, target=2, clip=2, axis=2), "hello", axis=2).type)
100 * var * 2 * union[{px: int64, py: int64, pz: int64}, string] (The type is now a union of records and strings.) >>> empty = ak.Record({"px": 0, "py": 0, "pz": 0})
>>> print(ak.fill_none(ak.pad_none(example, target=2, clip=2, axis=2), empty, axis=2).type)
100 * var * 2 * {px: int64, py: int64, pz: int64} (The type is just records.) |
Beta Was this translation helpful? Give feedback.
It becomes an option-type because it might need to insert
None
values to increase length-0 or length-1 lists to length-2.These lists are already length-2, but the type doesn't say that: the type is "var" (ragged). When you set
target=2
, it will increase any lists to reach length-2 by insertingNone
values, hence the option-type. Theclip=2
just ensures that any lists longer than 2 will be clipped. (Theaxis=2
is the depth, which, in this case, is also coincidentally 2.)