Trusted answers to developer questions

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.

In Python, we use the ** set_printoptions() function** to set the way floating-point number(s), array(s), and other NumPy objects are displayed.

```
set_printoptions(precision=None, threshold=None, edgeitems=None, suppress=None)
```

This function takes the following parameter values:

: This represents the number of digits of precision for floating-point output, which is optional, and the default value is`precision`

`8`

.: This represents the total number of array elements that trigger summarization rather than full`threshold`

`repr`

. This is optional with a default value of`1000`

.: This represents the number of array items in summary at the beginning and end of each dimension. This is optional and has a default value of`edgeitems`

`3`

.: This takes a Boolean value. If`suppress`

`True`

, the function will always print floating-point numbers using a fixed point notation. In this case, the numbers equal to zero in the current precision will print as zero. If`False`

, the scientific notation is used when the absolute value of the smallest is*<1e-4*or the ratio of the maximum absolute value to the minimum is*>1e3*. This is optional and with a default value of`False`

.

from numpy import set_printoptions, arange# setting the printing optionsset_printoptions(precision=4, threshold=5, edgeitems=3, suppress=True)# creating an array objectmyarray = arange(10)# printing the arayprint(myarray)

Implementing the set_printoptions() function

**Line 1**: We import`arange`

and`set_printoptions`

from the`numpy`

module.**Line 4**: We implement the`set_printoptions()`

function using a`precision`

value of`4`

,`threshold`

value of`5`

,`edgeitems`

value of`3`

and the`suppress`

value as`True`

. This sets the printing option of our code.**Line 7**: We use the`arange()`

function to create an array object`myarray`

with integers from`1`

to`9`

.**Line 10**: We print the array object`myarray`

.

RELATED TAGS

python

numpy

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

Related Courses