w3resource

NumPy Input and Output: array_str() function

numpy.array_str() function

The array_str() function is used to convert a given string representation of the data into an array.

This function is similar to array_repr, the difference being that array_repr also returns information on the kind of array and its data type.

Syntax:

numpy.array_str(a, max_line_width=None, precision=None, suppress_small=None)

Version: 1.15.0

Parameter:

Name Description Required /
Optional
a Input array.
ndarray
Required
max_line_width Inserts newlines if text is longer than max_line_width. The default is, indirectly, 75.
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 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.
bool
Optional

NumPy.array_str() method Example:

>>> import numpy as np
>>> np.array_str(np.arange(5))

Output:

'[0 1 2 3 4]'

Python - NumPy Code Editor:

Previous: array_repr() function
Next: format_float_positional() function



Share this Tutorial / Exercise on : Facebook and Twitter