ak.strings_astype#

Defined in awkward.operations.ak_strings_astype on line 18.

ak.strings_astype(array, to, *, highlevel=True, behavior=None, attrs=None)#
Parameters:
  • array – Array-like data (anything ak.to_layout recognizes).

  • to (dtype or dtype specifier) – Type to convert the strings into.

  • highlevel (bool) – If True, return an ak.Array; otherwise, return a low-level ak.contents.Content subclass.

  • behavior (None or dict) – Custom ak.behavior for the output array, if high-level.

  • attrs (None or dict) – Custom attributes for the output array, if high-level.

Converts all strings in the array to a new type, leaving the structure untouched.

For example,

>>> array = ak.Array(["1", "2", "    3    ", "00004", "-5"])
>>> ak.strings_astype(array, np.int32)
<Array [1, 2, 3, 4, -5] type='5 * int32'>

and

>>> array = ak.Array(["1.1", "2.2", "    3.3    ", "00004.4", "-5.5"])
>>> ak.strings_astype(array, np.float64)
<Array [1.1, 2.2, 3.3, 4.4, -5.5] type='5 * float64'>

and finally,

>>> array = ak.Array([["1.1", "2.2", "    3.3    "], [], ["00004.4", "-5.5"]])
>>> ak.strings_astype(array, np.float64)
<Array [[1.1, 2.2, 3.3], [], [4.4, -5.5]] type='3 * var * float64'>

See also ak.numbers_astype.