def _register_numpy_extensions(self):
import numpy as np<EOL>@self.register(np.ndarray)<EOL>def format_ndarray(data, **kwargs):<EOL><INDENT>import re<EOL>strvals = kwargs.get('<STR_LIT>', kwargs.get('<STR_LIT>', False))<EOL>itemsep = kwargs.get('<STR_LIT>', '<STR_LIT:U+0020>')<EOL>precision = kwargs.get('<STR_LIT>', None)<EOL>suppress_small = kwargs.get('<STR_LIT>', None)<EOL>max_line_width = kwargs.get('<STR_LIT>', None)<EOL>with_dtype = kwargs.get('<STR_LIT>', kwargs.get('<STR_LIT>', not strvals))<EOL>newlines = kwargs.pop('<STR_LIT>', kwargs.pop('<STR_LIT>', <NUM_LIT:1>))<EOL>separator = '<STR_LIT:U+002C>' + itemsep<EOL>if strvals:<EOL><INDENT>prefix = '<STR_LIT>'<EOL>suffix = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>modname = type(data).__module__<EOL>np_nice = '<STR_LIT>'<EOL>modname = re.sub('<STR_LIT>', np_nice, modname)<EOL>modname = re.sub('<STR_LIT>', '<STR_LIT>', modname)<EOL>class_name = type(data).__name__<EOL>if class_name == '<STR_LIT>':<EOL><INDENT>class_name = '<STR_LIT>'<EOL><DEDENT>prefix = modname + '<STR_LIT:.>' + class_name + '<STR_LIT:(>'<EOL>if with_dtype:<EOL><INDENT>dtype_repr = data.dtype.name<EOL>suffix = '<STR_LIT>'.format(itemsep, np_nice, dtype_repr)<EOL><DEDENT>else:<EOL><INDENT>suffix = '<STR_LIT:)>'<EOL><DEDENT><DEDENT>if not strvals and data.size == <NUM_LIT:0> and data.shape != (<NUM_LIT:0>,):<EOL><INDENT>prefix = modname + '<STR_LIT>'<EOL>body = repr(tuple(map(int, data.shape)))<EOL><DEDENT>else:<EOL><INDENT>body = np.array2string(data, precision=precision,<EOL>separator=separator,<EOL>suppress_small=suppress_small,<EOL>prefix=prefix,<EOL>max_line_width=max_line_width)<EOL><DEDENT>if not newlines:<EOL><INDENT>body = re.sub('<STR_LIT>', '<STR_LIT>', body)<EOL><DEDENT>formatted = prefix + body + suffix<EOL>return formatted<EOL><DEDENT>self.register(np.float32)(self.func_registry[float])<EOL>
CommandLine:
    python -m ubelt.util_format FormatterExtensions._register_numpy_extensions

Example:
    >>> import sys
    >>> import pytest
    >>> import ubelt as ub
    >>> if not ub.modname_to_modpath('numpy'):
    ...     raise pytest.skip()
    >>> # xdoctest: +IGNORE_WHITESPACE
    >>> import numpy as np
    >>> data = np.array([[.2, 42, 5], [21.2, 3, .4]])
    >>> print(ub.repr2(data))
    np.array([[ 0.2, 42. ,  5. ],
              [21.2,  3. ,  0.4]], dtype=np.float64)
    >>> print(ub.repr2(data, with_dtype=False))
    np.array([[ 0.2, 42. ,  5. ],
              [21.2,  3. ,  0.4]])
    >>> print(ub.repr2(data, strvals=True))
    [[ 0.2, 42. ,  5. ],
     [21.2,  3. ,  0.4]]
    >>> data = np.empty((0, 10), dtype=np.float64)
    >>> print(ub.repr2(data, strvals=False))
    np.empty((0, 10), dtype=np.float64)
    >>> print(ub.repr2(data, strvals=True))
    []
    >>> data = np.ma.empty((0, 10), dtype=np.float64)
    >>> print(ub.repr2(data, strvals=False))
    np.ma.empty((0, 10), dtype=np.float64)