Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

numpy
python
function
array_repr()
communitycreator

What is the array_repr() function from numpy in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

In Python, the array_repr() function is used to return a string representation of an array.

Syntax

array_repr(arr, precision=None, suppress_small=None)

Parameter

This function takes the following parameter values:

  • arr: This represents the input array.
  • precision: This represents the floating-point precision. It’s optional.
  • surpress_small: This represents the numbers very close to zero as zero. It takes Boolean values. The default value is False. This is also optional.

Return value

The array_repr() function returns the string representation of an array.

Example

from numpy import array_repr, array
# creating an array
my_array = array([1, 2, 3, 4, 5])
# implementing the array_repr() function
string_array = array_repr(my_array, precision = 6, suppress_small = True)
# printing the array
print(my_array)
# printing the string representation
print(string_array)
Implementing the array_repr() function

Explanation

  • Line 1: We import the numpy module.
  • Line 4: We use the array() function to create an array my_array.
  • Line 7: We implement the array_repr() function on the array my_array. To do that, we use a precision value, 6, and a suppress_small value of True. We assign the output to a new variable string_array.
  • Line 10: We print the array my_array.
  • Line 13: We print the string representation of the array string_array.

RELATED TAGS

numpy
python
function
array_repr()
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring