The array_str()
function in Python is used to return a string representation of the data in an array passed to it.
numpy.array_str(a, precision=None, suppress_small=None)
The array_str()
function takes the following parameter values:
a
: This represents the input array.precision
: This represents the floating point precision. This is optional.suppress_small
: This represents the numbers “very close” to zero as zero. It takes a Boolean value, and by default, the value is False
. This is optional.The array_str()
function returns the string representation of the data in an array.
import numpy as np# creating an arraymyarray = np.array([1, 2, 3, 4, 5])# implementing the array_str() functionstringrep = np.array_str(myarray, precision = 6, suppress_small = True)# printing the string representationprint(stringrep)print(type(stringrep))
numpy
module.myarray
using the array()
function.array_str()
method on the given array using a precision of 6
and a suppress_small
value as True
. The output is assigned to a new variable stringrep
.stringrep
.type()
function, we obtain the data type of the array stringrep
and print it.