numpy.array_repr() in Python (original) (raw)
Last Updated : 29 Nov, 2018
**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 characters split the string appropriately after array elements.
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
import
numpy as geek
arr
=
geek.array([
4
,
-
8
,
7
])
print
(
"Input array : "
, arr)
print
(
type
(arr))
out_arr
=
geek.array_repr(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
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_repr(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'
Similar Reads
- numpy.binary_repr() in Python numpy.binary_repr(number, width=None) function is used to represent binary form of the input number as a string. For negative numbers, if width is not given, a minus sign is added to the front. If width is given, the two’s complement of the number is returned, with respect to that width. In a two’s- 3 min read
- numpy.array_str() in Python 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_st 2 min read
- 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.base_repr() in Python numpy.base_repr(number, base=2, padding=0) function is used to return a string representation of a number in the given base system. For example, decimal number 10 is represented as 1010 in binary whereas it is represented as 12 in octal. Syntax : numpy.base_repr(number, base=2, padding=0) Parameters 3 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
- numpy.asanyarray() in Python numpy.asanyarray()function is used when we want to convert input to an array but it pass ndarray subclasses through. Input can be scalars, lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. Syntax : numpy.asanyarray(arr, dtype=None, order=None) Parameters : arr : [array_ 2 min read
- Python | Reverse a numpy array As we know Numpy is a general-purpose array-processing package that provides a high-performance multidimensional array object, and tools for working with these arrays. Let's discuss how can we reverse a Numpy array. Using flip() function to Reverse a Numpy array The numpy.flip() function reverses th 2 min read
- numpy.repeat() in Python The numpy.repeat() function repeats elements of the array - arr. Syntax : numpy.repeat(arr, repetitions, axis = None) Parameters : array : [array_like]Input array. repetitions : No. of repetitions of each array elements along the given axis. axis : Axis along which we want to repeat values. By defau 2 min read
- numpy.array_equiv() in Python numpy.array_equiv(arr1, arr2) : This logical function that checks if two arrays have the same elements and shape consistent. Shape consistent means either they are having the same shape, or one input array can be broadcasted to create the same shape as the other one. Parameters : arr1 : [array_like] 2 min read