str2d.Str2D.struct_array_from_string
- classmethod Str2D.struct_array_from_string(string: str, **kwargs) Str2D [source]
Create a structured array from a string. This is likely the most common way to create an Str2D object. The string is split into lines and then each line is split into characters. The structured array is created with fields ‘char’ and ‘alpha’ where the ‘char’ field contains the characters and the ‘alpha’ field contains 1 for each character.
Though we aren’t returning a Str2D object, we are returning a structured array that potentially needs to be padded and therefore we take the same keyword arguments as the Str2D constructor.
- Parameters:
string (str) – A string to convert to a structured array.
min_width (int, optional) – The minimum width of the output, by default 0.
min_height (int, optional) – The minimum height of the output, by default 0.
halign (str, optional) – The horizontal alignment, by default ‘left’.
valign (str, optional) – The vertical alignment, by default ‘top’.
fill (Tuple[str, int], optional) – The fill value for the ‘char’ and ‘alpha’ fields, by default (’ ‘, 0).
- Returns:
A structured array with fields ‘char’ and ‘alpha’ created from the input string.
- Return type:
np.ndarray