numpy.trunc(x[, out]) = ufunc ‘trunc’) : This mathematical function returns the truncated value of the elements of array. The trunc of the scalar x is the nearest integer i which, closer to zero than x. This simply means that, the fractional part of the signed number x is discarded by this function.
a : [array_like] Input array
The truncated of each element, with float data-type
Code #1 : Working
Input array : [0.5, 1.5, 2.5, 3.5, 4.5, 10.1] Rounded values : [ 0. 1. 2. 3. 4. 10.] Input array : [0.53, 1.54, 0.71] Rounded values : [ 0. 1. 0.] Input array : [0.5538, 1.33354, 0.71445] Rounded values : [ 0. 1. 0.]
Code 2 : Working
Input array : [1.67, 4.5, 7, 9, 12] Rounded values : [ 1. 4. 7. 9. 12.] Input array : [133.0, 344.54, 437.56, 44.9, 1.2] Rounded values upto 2: [ 133. 344. 437. 44. 1.]
- Important differences between Python 2.x and Python 3.x with examples
- Python | Sort Python Dictionaries by Key or Value
- Python | Set 4 (Dictionary, Keywords in Python)
- abs() in Python
- Any & All in Python
- max() and min() in Python
- SQL using Python | Set 1
- Python Set | pop()
- SHA in Python
- bin() in Python
- set add() in python
- try and except in Python
- gcd() in Python
- pow() in Python
- chr() in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.