numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturns
array2string(a, max_line_width=None, precision=None, suppress_small=None, separator=' ', prefix='', style=<no value>, formatter=None, threshold=None, edgeitems=None, sign=None, floatmode=None, suffix='', *, legacy=None)

Notes

If a formatter is specified for a certain type, the :None:None:`precision` keyword is ignored for that type.

This is a very flexible function; array_repr and array_str are using array2string internally so keywords with the same name should work identically in all three functions.

Parameters

a : ndarray

Input array.

max_line_width : int, optional

Inserts newlines if text is longer than :None:None:`max_line_width`. Defaults to numpy.get_printoptions()['linewidth'] .

precision : int or None, optional

Floating point precision. Defaults to numpy.get_printoptions()['precision'] .

suppress_small : bool, optional

Represent numbers "very close" to zero as zero; default is False. Very close is defined by precision: if the precision is 8, e.g., numbers smaller (in absolute value) than 5e-9 are represented as zero. Defaults to numpy.get_printoptions()['suppress'] .

separator : str, optional

Inserted between elements.

prefix : str, optional
suffix : str, optional

The length of the prefix and suffix strings are used to respectively align and wrap the output. An array is typically printed as:

prefix + array2string(a) + suffix

The output is left-padded by the length of the prefix string, and wrapping is forced at the column max_line_width - len(suffix) . It should be noted that the content of prefix and suffix strings are not included in the output.

style : _NoValue, optional

Has no effect, do not use.

deprecated
formatter : dict of callables, optional

If not None, the keys should indicate the type(s) that the respective formatting function applies to. Callables should return a string. Types that are not specified (by their corresponding keys) are handled by the default formatters. Individual types for which a formatter can be set are:

threshold : int, optional

Total number of array elements which trigger summarization rather than full repr. Defaults to numpy.get_printoptions()['threshold'] .

edgeitems : int, optional

Number of array items in summary at beginning and end of each dimension. Defaults to numpy.get_printoptions()['edgeitems'] .

sign : string, either '-', '+', or ' ', optional

Controls printing of the sign of floating-point types. If '+', always print the sign of positive values. If ' ', always prints a space (whitespace character) in the sign position of positive values. If '-', omit the sign character of positive values. Defaults to numpy.get_printoptions()['sign'] .

floatmode : str, optional

Controls the interpretation of the :None:None:`precision` option for floating-point types. Defaults to numpy.get_printoptions()['floatmode'] . Can take the following values:

  • 'fixed': Always print exactly :None:None:`precision` fractional digits, even if this would print more or fewer digits than necessary to specify the value uniquely.

  • 'unique': Print the minimum number of fractional digits necessary to represent each value uniquely. Different elements may have a different number of digits. The value of the :None:None:`precision` option is ignored.

  • 'maxprec': Print at most :None:None:`precision` fractional digits, but if an element can be uniquely represented with fewer digits only print it with that many.

  • 'maxprec_equal': Print at most :None:None:`precision` fractional digits, but if every element in the array can be uniquely represented with an equal number of fewer digits, use that many digits for all elements.

legacy : string or `False`, optional

If set to the string :None:None:`'1.13'` enables 1.13 legacy printing mode. This approximates numpy 1.13 print output by including a space in the sign position of floats and different behavior for 0d arrays. If set to :None:None:`False`, disables legacy mode. Unrecognized strings will be ignored with a warning for forward compatibility.

versionadded

Raises

TypeError

if a callable in formatter does not return a string.

Returns

array_str : str

String representation of the array.

Return a string representation of an array.

See Also

array_repr
array_str
get_printoptions
set_printoptions

Examples

>>> x = np.array([1e-16,1,2,3])
... np.array2string(x, precision=2, separator=',',
...  suppress_small=True) '[0.,1.,2.,3.]'
>>> x  = np.arange(3.)
... np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x}) '[0.00 1.00 2.00]'
>>> x  = np.arange(3)
... np.array2string(x, formatter={'int':lambda x: hex(x)}) '[0x0 0x1 0x2]'
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/arrayprint.py#561
type: <class 'function'>
Commit: