numpy.array_str() in Python Last Updated : 29 Nov, 2018 Comments Improve Suggest changes Like Article Like Report numpy.array_str()function is used to represent the data of an array as a string. The data in the array is returned as a single string. 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(arr, max_line_width=None, precision=None, suppress_small=None) Parameters : arr : [array_like] Input array. max_line_width : [int, optional] Inserts newlines if text is longer than max_line_width. The default is, indirectly, 75. precision : [int, optional] Floating point precision. Default is the current printing precision(generally 8). suppress_small : [bool, optional] It represent very small numbers as zero, default is False. Very small number is defined by precision, if the precision is 8 then numbers smaller than 5e-9 are represented as zero. Return : [str] The string representation of an array. Code #1 : Working Python # Python program explaining # array_str() function import numpy as geek arr = geek.array([4, -8, 7 ]) print ("Input array : ", arr) print(type(arr)) out_arr = geek.array_str(arr) print ("The string representation of input array : ", out_arr) print(type(out_arr)) Output : Input array : [ 4 -8 7] class 'numpy.ndarray' The string representation of input array : array([ 4, -8, 7]) class 'str' Code #2 : Working Python # Python program explaining # array_str() function import numpy as geek in_arr = geek.array([5e-8, 4e-7, 8, -4]) print ("Input array : ", in_arr) print(type(in_arr)) out_arr = geek.array_str(in_arr, precision = 6, suppress_small = True) print ("The string representation of input array : ", out_arr) print(type(out_arr)) Output : Input array : [ 5.00000000e-08 4.00000000e-07 8.00000000e+00 -4.00000000e+00] class 'numpy.ndarray' The string representation of input array : array([ 0., 0., 8., -4.]) class 'str' Comment More infoAdvertise with us Next Article numpy.array_str() in Python J jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-io Practice Tags : python Similar Reads NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read numpy.array_repr() in Python numpy.array_repr()function is used to convert an array to a string. Syntax : numpy.array_repr(arr, max_line_width=None, precision=None, suppress_small=None) Parameters : arr : [array_like] Input array. max_line_width : [int, optional] The maximum number of columns the string should span. Newline cha 2 min read numpy.asarray() in Python numpy.asarray()function is used when we want to convert input to an array. Input can be lists, lists of tuples, tuples, tuples of tuples, tuples of lists and arrays. Syntax : numpy.asarray(arr, dtype=None, order=None) Parameters : arr : [array_like] Input data, in any form that can be converted to a 2 min read numpy.asfarray() in Python numpy.asfarray()function is used when we want to convert input to a float type array. Input includes scalar, lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. Syntax : numpy.asfarray(arr, dtype=type 'numpy.float64') Parameters : arr : [array_like] Input data, in any for 2 min read Python Lists VS Numpy Arrays Here, we will understand the difference between Python List and Python Numpy array. What is a Numpy array?NumPy is the fundamental package for scientific computing in Python. Numpy arrays facilitate advanced mathematical and other types of operations on large numbers of data. Typically, such operati 7 min read Like