ak.full_like#
Defined in awkward.operations.ak_full_like on line 20.
- ak.full_like(array, fill_value, *, dtype=None, including_unknown=False, highlevel=True, behavior=None, attrs=None)#
- Parameters:
array – Array-like data (anything
ak.to_layoutrecognizes).fill_value – Value to fill the new array with.
dtype (None or NumPy dtype) – Overrides the data type of the result.
including_unknown (bool) – If True, the
unknowntype is considered a value type and is converted to a zero-length array of the specified dtype; if False,unknownwill remainunknown.highlevel (bool, default is True) – If True, return an
ak.Array; otherwise, return a low-levelak.contents.Contentsubclass.behavior (None or dict) – Custom
ak.behaviorfor the output array, if high-level.attrs (None or dict) – Custom attributes for the output array, if high-level.
This is the equivalent of NumPy’s
np.full_likefor Awkward Arrays.Although it’s possible to produce an array of
fill_valuewith the structure of anarrayusingak.broadcast_arrays:>>> array = ak.Array([[1, 2, 3], [], [4, 5]]) >>> ak.broadcast_arrays(array, 1) [<Array [[1, 2, 3], [], [4, 5]] type='3 * var * int64'>, <Array [[1, 1, 1], [], [1, 1]] type='3 * var * int64'>] >>> ak.broadcast_arrays(array, 1.0) [<Array [[1, 2, 3], [], [4, 5]] type='3 * var * int64'>, <Array [[1, 1, 1], [], [1, 1]] type='3 * var * float64'>]
Such a technique takes its type from the scalar (
1or1.0), rather than the array. This function gets all types from the array, which might not be the same in all parts of the structure.Here is an extreme example:
>>> array = ak.Array([ ... [{"x": 0.0, "y": []}, ... {"x": 1.1, "y": [1]}, ... {"x": 2.2, "y": [1, 2]}], ... [], ... [{"x": 3.3, "y": [1, 2, None, 3]}, ... False, ... False, ... True, ... {"x": 4.4, "y": [1, 2, None, 3, 4]}]]) >>> ak.full_like(array, 12.3).show() [[{x: 12.3, y: []}, {x: 12.3, y: [12]}, {x: 12.3, y: [12, 12]}], [], [{x: 12.3, y: [12, 12, None, 12]}, True, ..., True, {x: 12.3, y: [12, ...]}]]
The
"x"values get filled in with12.3because they retain their type (float64) and the"y"list items get filled in with12because they retain their type (int64). Booleans get filled with True because12.3is not zero. Missing values remain in the same positions as in the originalarray. (To fill them in, useak.fill_none.)See also
ak.zeros_likeandak.ones_like.(There is no equivalent of NumPy’s
np.empty_likebecause Awkward Arrays are immutable.)