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.

The ** numpy.trunc()** function in NumPy is used to return the nearest integer

`i`

of elements in an input array `x`

. In other words, the fractional part of each signed value of each element in `x`

is discarded.```
numpy.trunc(x, /, out=None, *, where=True)
```

The `numpy.trunc()`

function takes the following parameter values:

(required): This represents the input array.`x`

(optional): This represents the location where the result is stored.`out`

(optional): This is the condition over which the input is being broadcast. At a given location where this condition is`where`

`True`

, the resulting array will be set to the`ufunc`

result. Otherwise, the resulting array will retain its original value.(optional): This represents other keyword arguments.`**kwargs`

The `numpy.trunc()`

function returns a truncated value of each element in the input array `x`

.

import numpy as np# creating an arrayx = np.array([-1.5, 10.3, -6.6, 0.9, 180.05])# obtaining the truncated valuesmyarray = np.trunc(x)print(x)print(myarray)

Implementing the numpy.trunc() function

- Line 1: We import the
`numpy`

module. - Line 4: We create an array
`x`

using the`array()`

method. - Line 7: We implement the
`np.trunc()`

function on the array. The result is assigned to a variable`myarray`

. - Line 9: We print the input array
`x`

. - Line 10: We print the variable
`myarray`

.

RELATED TAGS

function

numpy

python

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