Try out this modified version of numpy.trunc().

import numpy as np
def trunc(values, decs=0):
    return np.trunc(values*10**decs)/(10**decs)

Sadly, numpy.trunc function doesn't allow decimal truncation. Luckily, multiplying the argument and dividing it's result by a power of ten give the expected results.

vec = np.array([-4.79, -0.38, -0.001, 0.011, 0.4444, 2.34341232, 6.999])

trunc(vec, decs=2)

which returns:

>>> array([-4.79, -0.38, -0.  ,  0.01,  0.44,  2.34,  6.99])
Answer from Wolphyrus Imperius on Stack Overflow
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v2.5.dev0 Manual
The truncated value of each element in x. This is a scalar if x is a scalar. ... Try it in your browser! >>> import numpy as np >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) >>> np.trunc(a) array([-1., -1., -0., 0., 1., 1., 2.])
Release notes
Fundamentals and usage · Advanced usage and interoperability
Constants
NumPy includes several constants: · Euler’s number, base of natural logarithms, Napier’s constant
Linear algebra
The NumPy linear algebra functions rely on BLAS and LAPACK to provide efficient low level implementations of standard linear algebra algorithms. Those libraries may be provided by NumPy itself using C versions of a subset of their reference implementations but, when possible, highly optimized ...
numpy.arctan
Trigonometric inverse tangent, element-wise · The inverse of tan, so that if y = tan(x) then x = arctan(y)
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v2.4 Manual
The truncated value of each element in x. This is a scalar if x is a scalar. ... Try it in your browser! >>> import numpy as np >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) >>> np.trunc(a) array([-1., -1., -0., 0., 1., 1., 2.])
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-trunc-python
numpy.trunc() in Python - GeeksforGeeks
March 8, 2024 - The numpy.trunc() is a mathematical function that 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.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v2.2 Manual
The truncated value of each element in x. This is a scalar if x is a scalar. ... >>> import numpy as np >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) >>> np.trunc(a) array([-1., -1., -0., 0., 1., 1., 2.])
🌐
Codecademy
codecademy.com › docs › python:numpy › math methods › .trunc()
Python:NumPy | Math Methods | .trunc() | Codecademy
November 27, 2024 - In NumPy, the .trunc() function truncates the decimal part of each element in an array, returning the integer part as a float.
🌐
NumPy
numpy.org › doc › 1.21 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v1.21 Manual
numpy.trunc(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'trunc'>¶
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v2.1 Manual
The truncated value of each element in x. This is a scalar if x is a scalar. ... New in version 1.3.0. ... >>> import numpy as np >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) >>> np.trunc(a) array([-1., -1., -0., 0., 1., 1., 2.])
🌐
NumPy
numpy.org › doc › 1.22 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v1.22 Manual
numpy.trunc(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'trunc'>¶
Find elsewhere
🌐
NumPy
numpy.org › doc › 1.20 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v1.20 Manual
numpy.trunc(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'trunc'>¶
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v2.3 Manual
The truncated value of each element in x. This is a scalar if x is a scalar. ... Try it in your browser! >>> import numpy as np >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) >>> np.trunc(a) array([-1., -1., -0., 0., 1., 1., 2.])
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v2.0 Manual
numpy.trunc(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'trunc'>#
🌐
NumPy
numpy.org › doc › 1.25 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v1.25 Manual
numpy.trunc(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'trunc'>#
🌐
NumPy
numpy.org › doc › 1.16 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v1.16 Manual
numpy.trunc(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'trunc'>¶
🌐
Educative
educative.io › answers › what-is-the-numpytrunc-function-in-numpy
What is the numpy.trunc() function in Numpy?
The numpy.trunc() function in NumPy is used to return the nearest integer i of elements in an input array x.
🌐
SciPy
docs.scipy.org › doc › numpy-1.10.0 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v1.10 Manual
numpy.trunc(x[, out]) = <ufunc 'trunc'>¶ · Return the truncated value of the input, element-wise. The truncated value of the scalar x is the nearest integer i which is closer to zero than x is. In short, the fractional part of the signed number x is discarded.
🌐
AskPython
askpython.com › home › numpy trunc() – return the truncated value of the input, element-wise
Numpy trunc() - Return the truncated value of the input, element-wise - AskPython
November 19, 2022 - The numpy.trunc() function is used to return the truncated value of the input element, i.e. the integer part of the input element. If we have an input array, this function returns the truncated value for each element in the array.
🌐
NumPy
numpy.org › doc › 1.18 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v1.18 Manual
May 24, 2020 - numpy.trunc(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'trunc'>¶
🌐
SciPy
docs.scipy.org › doc › numpy-1.11.0 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v1.11 Manual
numpy.trunc(x[, out]) = <ufunc 'trunc'>¶ · Return the truncated value of the input, element-wise. The truncated value of the scalar x is the nearest integer i which is closer to zero than x is. In short, the fractional part of the signed number x is discarded.
🌐
NumPy
numpy.org › doc › 1.15 › reference › generated › numpy.trunc.html
numpy.trunc — NumPy v1.15 Manual
November 4, 2018 - numpy.trunc(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'trunc'>¶