Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.array2string

numpy.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='',**kwarg)[source]

Return a string representation of an array.

Parameters:
a:array_like

Input array.

max_line_width:int, optional

The maximum number of columns the string should span. Newlinecharacters splits the string appropriately after array elements.

precision:int or None, optional

Floating point precision. Default is the current printingprecision (usually 8), which can be altered usingset_printoptions.

suppress_small:bool, optional

Represent very small numbers as zero. A number is “very small” if itis smaller than the current printing precision.

separator:str, optional

Inserted between elements.

prefix:str, optional
suffix: str, optional

The length of the prefix and suffix strings are used to respectivelyalign 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, andwrapping is forced at the columnmax_line_width-len(suffix).

style:_NoValue, optional

Has no effect, do not use.

Deprecated since version 1.14.0.

formatter:dict of callables, optional

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

  • ‘bool’
  • ‘int’
  • ‘timedelta’ : anumpy.timedelta64
  • ‘datetime’ : anumpy.datetime64
  • ‘float’
  • ‘longfloat’ : 128-bit floats
  • ‘complexfloat’
  • ‘longcomplexfloat’ : composed of two 128-bit floats
  • ‘void’ : typenumpy.void
  • ‘numpystr’ : typesnumpy.string_ andnumpy.unicode_
  • ‘str’ : all other strings

Other keys that can be used to set a group of types at once are:

  • ‘all’ : sets all types
  • ‘int_kind’ : sets ‘int’
  • ‘float_kind’ : sets ‘float’ and ‘longfloat’
  • ‘complex_kind’ : sets ‘complexfloat’ and ‘longcomplexfloat’
  • ‘str_kind’ : sets ‘str’ and ‘numpystr’
threshold:int, optional

Total number of array elements which trigger summarizationrather than full repr.

edgeitems:int, optional

Number of array items in summary at beginning and end ofeach dimension.

sign:string, either ‘-‘, ‘+’, or ‘ ‘, optional

Controls printing of the sign of floating-point types. If ‘+’, alwaysprint 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.

floatmode:str, optional

Controls the interpretation of theprecision option forfloating-point types. Can take the following values:

  • ‘fixed’: Always print exactlyprecision fractional digits,even if this would print more or fewer digits thannecessary to specify the value uniquely.
  • ‘unique’: Print the minimum number of fractional digits necessaryto represent each value uniquely. Different elements mayhave a different number of digits. The value of theprecision option is ignored.
  • ‘maxprec’: Print at mostprecision fractional digits, but ifan element can be uniquely represented with fewer digitsonly print it with that many.
  • ‘maxprec_equal’: Print at mostprecision fractional digits,but if every element in the array can be uniquelyrepresented with an equal number of fewer digits, use thatmany digits for all elements.
legacy:string orFalse, optional

If set to the string‘1.13’ enables 1.13 legacy printing mode. Thisapproximates numpy 1.13 print output by including a space in the signposition of floats and different behavior for 0d arrays. If set toFalse, disables legacy mode. Unrecognized strings will be ignoredwith a warning for forward compatibility.

New in version 1.14.0.

Returns:
array_str:str

String representation of the array.

Raises:
TypeError

if a callable informatter does not return a string.

Notes

If a formatter is specified for a certain type, theprecision keyword isignored for that type.

This is a very flexible function;array_repr andarray_str are usingarray2string internally so keywords with the same name should workidentically in all three functions.

Examples

>>>x=np.array([1e-16,1,2,3])>>>print(np.array2string(x,precision=2,separator=',',...suppress_small=True))[ 0., 1., 2., 3.]
>>>x=np.arange(3.)>>>np.array2string(x,formatter={'float_kind':lambdax:"%.2f"%x})'[0.00 1.00 2.00]'
>>>x=np.arange(3)>>>np.array2string(x,formatter={'int':lambdax:hex(x)})'[0x0L 0x1L 0x2L]'

Previous topic

numpy.fromregex

Next topic

numpy.array_repr

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp