numpy.trapz() function | Python Last Updated : 26 Mar, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report numpy.trapz() function integrate along the given axis using the composite trapezoidal rule. Syntax : numpy.trapz(y, x = None, dx = 1.0, axis = -1) Parameters : y : [array_like] Input array to integrate. x : [array_like, optional] The sample points corresponding to the y values. If x is None, the sample points are assumed to be evenly spaced dx apart. The default is None. dx : [scalar, optional] The spacing between sample points when x is None. The default is 1. axis : [int, optional] The axis along which to integrate. Return : trapz: [float] Definite integral as approximated by trapezoidal rule. Code #1 : Python3 # Python program explaining # numpy.trapz() function # importing numpy as geek import numpy as geek y = [1, 2, 3, 4] gfg = geek.trapz( y ) print (gfg) Output : 7.5 Code #2 : Python3 # Python program explaining # numpy.trapz() function # importing numpy as geek import numpy as geek y = [1, 2, 3, 4] x = [5, 6, 7, 8] gfg = geek.trapz(y, x) print (gfg) Output : 7.5 Code #3 : Python3 # Python program explaining # numpy.trapz() function # importing numpy as geek import numpy as geek y = [1, 2, 3, 4] gfg = geek.trapz(y, dx = 2) print (gfg) Output : 15.0 Comment More infoAdvertise with us Next Article Numpy - String Functions & Operations S sanjoy_62 Follow Improve Article Tags : Machine Learning Python-numpy python Practice Tags : Machine Learningpython Similar Reads numpy.ma.where() function - Python numpy.ma.where() function return a masked array with elements from x or y, depending on condition. Syntax : numpy.ma.where(condition, x, y) Parameter : condition : [array_like, bool] Where True, yield x, otherwise yield y. x, y : [array_like, optional] Values from which to choose. x, y and condition 1 min read Numpy - String Functions & Operations NumPy String functions belong to the numpy.char module and are designed to perform element-wise operations on arrays. These functions can help to handle and manipulate string data efficiently.Table of ContentString OperationsString Information String Comparison In this article, weâll explore the var 5 min read Numpy MaskedArray.ravel() function | Python numpy.MaskedArray.ravel() function is used to return a 1D version of self mask array, as a view. Syntax : numpy.ma.ravel(self, order='C') Parameters: order : [âCâ, âFâ, âAâ, âKâ, optional] By default, âCâ index order is used. --> The elements of a are read using this index order. --> âCâ means to in 2 min read numpy.trim_zeros() in Python numpy.trim_zeros() removes the leading and trailing zeros from a 1-D array. It is often used to clean up data by trimming unnecessary zeros from the beginning or end of the array. Example:Pythonimport numpy as np a = np.array([0, 0, 3, 4, 0, 5, 0, 0]) res = np.trim_zeros(a) print(res)Output[3 4 0 5] 2 min read numpy.frompyfunc() in Python numpy.frompyfunc(func, nin, nout) function allows to create an arbitrary Python function as Numpy ufunc (universal function). Parameters: func: [A python function object ] An arbitrary python function nin: [int] Number of input arguments to that function. nout: [int] Number of objects returned by th 2 min read Numpy ndarray.tobytes() function | Python numpy.ndarray.tobytes() function construct Python bytes containing the raw data bytes in the array. Syntax : numpy.ndarray.tobytes(order='C') Parameters : order : [{âCâ, âFâ, None}, optional] Order of the data for multidimensional arrays: C, Fortran, or the same as for the original array. Return : P 1 min read Like