Python scipy 模块,diff() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用scipy.diff()

项目:Wind-Turbine-Design    作者:doublerob7    | 项目源码 | 文件源码
def plot_pdf_fit(self, label=None):
        import matplotlib.pyplot as plt
        from scipy.stats import exponweib, rayleigh
        from scipy import linspace, diff

        plt.bar(self.pdf[1][:len(self.pdf[0])], self.pdf[0], width=diff(self.pdf[1]), label=label, alpha=0.5, color='k')

        x = linspace(0, 50, 1000)

        plt.plot(x, exponweib.pdf(x, a=self.weibull_params[0], c=self.weibull_params[1], scale=self.weibull_params[3]),
                 'b--', label='Exponential Weibull pdf')
        plt.plot(x, rayleigh.pdf(x, scale=self.rayleigh_params[1]), 'r--', label='Rayleigh pdf')

        plt.title('Normalized distribution of wind speeds')
        plt.grid()
        plt.legend()
项目:house-price-map    作者:andyljones    | 项目源码 | 文件源码
def get_edges(routes):
    results = []
    for timetable in walk_timetables(routes):
        origin = timetable['timetable']['departureStopId']
        for route in timetable['timetable']['routes']:
            for intervals in route['stationIntervals']:
                stops = [origin] + [x['stopId'] for x in intervals['intervals']]
                edges = [[s, t] for s, t in zip(stops, stops[1:])]

                times = [0] + [x['timeToArrival'] for x in intervals['intervals']]
                weights = list(sp.diff(sp.array(times)))

                results.extend([[s, t, w] for (s, t), w in zip(edges, weights)])

    results = pd.DataFrame(results, columns=['origin', 'destination', 'time'])
    results = results.groupby(['origin', 'destination']).mean()

    return results
项目:Wind-Turbine-Design    作者:doublerob7    | 项目源码 | 文件源码
def plot_pdf_fit(self, label=None):
        import matplotlib.pyplot as plt
        from scipy.stats import exponweib, rayleigh
        from scipy import linspace, diff

        plt.bar(self.pdf[1][:len(self.pdf[0])], self.pdf[0], width=diff(self.pdf[1]), label=label, alpha=0.5, color='k')

        x = linspace(0, 50, 1000)

        plt.plot(x, exponweib.pdf(x, a=self.weibull_params[0], c=self.weibull_params[1], scale=self.weibull_params[3]), 'b--', label='Exponential Weibull pdf')
        plt.plot(x, rayleigh.pdf(x, scale=self.rayleigh_params[1]), 'r--', label='Rayleigh pdf')

        plt.title('Normalized distribution of wind speeds')
        plt.grid()
        plt.legend()
项目:python-psignifit    作者:wichmann-lab    | 项目源码 | 文件源码
def getWeights(X1D):

    d = len(X1D)

    ''' puts the X values in their respective dimensions to use bsxfun for
    evaluation'''
    Xreshape = []
    Xreshape.append(X1D[0].reshape(-1,1))
    if d >= 2:
        Xreshape.append(X1D[1].reshape([1,-1]))

    for idx in range (2,d):
        dims = [1]*idx
        dims.append(-1)
        Xreshape.append(reshape(X1D[idx], dims))


    # to find and handle singleton dimensions
    sizes = [X1D[ix].size for ix in range(0,d)]
    Xlength = array(sizes)

    ''' calculate weights '''
    #1) calculate mass/volume for each cuboid
    weight = 1
    for idx in range(0,d):
        if Xlength[idx] > 1:
            if idx > 1:
                weight = multiply(weight[...,newaxis],diff(Xreshape[idx], axis=idx))
            else:
                weight = multiply(weight,diff(Xreshape[idx], axis=idx))
        else:
            weight = weight[...,newaxis]
    #2) sum to get weight for each point
    if d > 1:
        dims = tile(2,[1,d])
        dims[0,where(Xlength == 1)] = 1
        d = sum(Xlength > 1)
        weight = (2.**(-d))*convn(weight, ones(dims.ravel()), mode='full')
    else:
        weight = (2.**(-1))*convolve(weight, array([[1],[1]]))

    return weight