w3resource

NumPy Input and Output: array_repr() function

numpy.array_repr() function

The array_repr() function is used to get the string representation of an array.

Syntax:

numpy.array_repr(arr, max_line_width=None, precision=None, suppress_small=None)

Version: 1.15.0

Parameter:

Name Description Required /
Optional
arr Input array.
ndarray
Required
max_line_width The maximum number of columns the string should span.
Newline characters split the string appropriately after array elements.
int
Optional
precision Floating point precision.
Default is the current printing precision (usually 8), which can be altered using set_printoptions.
int
Optional
suppress_small Represent very small numbers as zero, default is False.
Very small is defined by precision, if the precision is 8 then numbers smaller than 5e-9 are represented as zero.
bool
Optional

Returns: string : str
The string representation of an array.

NumPy.array_repr() method Example-1:

>>> import numpy as np
>>> np.array_repr(np.array([2,4]))

Output:

'array([2, 4])'

NumPy.array_repr() method Example-2:

>>> import numpy as np
>>> np.array_repr(np.ma.array([0.]))

Output:

'MaskedArray([ 0.])'

NumPy.array_repr() method Example-3:

>>> import numpy as np
>>> np.array_repr(np.array([], np.int32))

Output:

'array([], dtype=int32)'

NumPy.array_repr() method Example-4:

>>> import numpy as np
>>> a = np.array([1e-6, 4e-7, 3, 5])
>>> np.array_repr(a, precision=6, suppress_small=True)

Output:

'array([0.000001, 0.      , 3.      , 5.      ])'

Python - NumPy Code Editor:

Previous: array2string() function
Next: array_str() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/numpy/input-and-output/array_repr.php