• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.cumprod函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.cumprod函数的典型用法代码示例。如果您正苦于以下问题:Python cumprod函数的具体用法?Python cumprod怎么用?Python cumprod使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了cumprod函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _indtosub_converter

def _indtosub_converter(dims, order='F', onebased=True):
    """Converter for changing linear indexing to subscript indexing

    See also
    --------
    Series.indtosub
    """

    _check_order(order)

    def indtosub_inline_onebased(k, dimprod):
        return tuple(map(lambda (x, y): int(mod(ceil(float(k)/y) - 1, x) + 1), dimprod))

    def indtosub_inline_zerobased(k, dimprod):
        return tuple(map(lambda (x, y): int(mod(ceil(float(k+1)/y) - 1, x)), dimprod))

    inline_fcn = indtosub_inline_onebased if onebased else indtosub_inline_zerobased

    if size(dims) > 1:
        if order == 'F':
            dimprod = zip(dims, append(1, cumprod(dims)[0:-1]))
        else:
            dimprod = zip(dims, append(1, cumprod(dims[::-1])[0:-1])[::-1])
        converter = lambda k: inline_fcn(k, dimprod)
    else:
        converter = lambda k: (k,)

    return converter
开发者ID:Young-china,项目名称:thunder,代码行数:28,代码来源:keys.py


示例2: _update_attributes

    def _update_attributes(self):
        getitem_tuple = ()
        values = []
        self.signal_axes = ()
        self.navigation_axes = ()
        for axis in self._axes:
            # Until we find a better place, take property of the axes
            # here to avoid difficult to debug bugs.
            axis.axes_manager = self
            if axis.slice is None:
                getitem_tuple += (axis.index,)
                values.append(axis.value)
                self.navigation_axes += (axis,)
            else:
                getitem_tuple += (axis.slice,)
                self.signal_axes += (axis,)

        self.signal_axes = self.signal_axes[::-1]
        self.navigation_axes = self.navigation_axes[::-1]
        self._getitem_tuple = getitem_tuple
        self.signal_dimension = len(self.signal_axes)
        self.navigation_dimension = len(self.navigation_axes)
        if self.navigation_dimension != 0:
            self.navigation_shape = tuple([axis.size for axis in self.navigation_axes])
        else:
            self.navigation_shape = ()

        if self.signal_dimension != 0:
            self.signal_shape = tuple([axis.size for axis in self.signal_axes])
        else:
            self.signal_shape = ()
        self.navigation_size = np.cumprod(self.navigation_shape)[-1] if self.navigation_shape else 0
        self.signal_size = np.cumprod(self.signal_shape)[-1] if self.signal_shape else 0
        self._update_max_index()
开发者ID:jerevon,项目名称:hyperspy,代码行数:34,代码来源:axes.py


示例3: plot2

    def plot2(indx_Exposure, indx_MarketRet):
        plt.clf()

        MarketReturns = plt.subplot2grid((8,8), (0,0), colspan=6, rowspan=8)
        t = np.array(DATEord)

        if indx_Exposure == 2:
            mRet = np.cumprod(1-marketRet[indx_MarketRet + cashOffset])
        else:
            mRet = np.cumprod(1+marketRet[indx_MarketRet + cashOffset])

        MarketReturns.plot(t, mRet, 'b',linewidth=0.5)
        statistics=stats(mRet)
        MarketReturns.set_ylabel('Market Returns')

        statsStr="Sharpe Ratio = {sharpe:.4f}\nSortino Ratio = {sortino:.4f}\n\nPerformance (%/yr) = {returnYearly:.4f}\nVolatility (%/yr)       = {volaYearly:.4f}\n\nMax Drawdown = {maxDD:.4f}\nMAR Ratio         = {mar:.4f}\n\n Max Time off peak =  {maxTimeOffPeak}\n\n\n\n\n\n".format(**statistics)

        MarketReturns.autoscale(tight=True)
        MarketReturns.set_title('Market Returns of %s' %mRetMarkets[indx_MarketRet])
        MarketReturns.set_xlabel('Date')

        # Performance Numbers Textbox
        f.text(.72,.58,statsStr)

        plt.gcf().canvas.draw()
开发者ID:marcoracer,项目名称:quantiacs-python,代码行数:25,代码来源:quantiacsToolbox.py


示例4: panda_index

def panda_index(labels, names=None, dtype='|S10'):
    """
    Create a pandas.MultiIndex with row names contained in the nested 
    list `labels` and column names contained in the optional list 
    `names`.
    
    Args:
        labels: nested list of strings
        names: list of strings
    
    Example usage:
        >>> labels = [['wine','water','beer'], [0.2','0.5'], ['to go','for here']]
        >>> names = ['beverage','size','order']
        >>> index = make_index(labels,names)
        >>> index
        
    """
    if names==None:
        names = ['axis{0}'.format(i) for i in range(len(labels))]
    else:
        assert len(labels)==len(names)
    sh = list_shape(labels)
    n_axes = len(labels)
    n_total = np.prod(sh)
    ctile = np.concatenate( ([1],np.cumprod(sh)[:-1]) )
    crep = np.concatenate( (np.cumprod(sh[::-1])[:-1][::-1],[1]) )
    replabels = np.empty((n_axes,n_total), dtype=dtype)
    for i,l in enumerate(labels):
        replabels[i] = np.tile( np.repeat(l,crep[i]), ctile[i] )
    tuples = zip(*replabels)
    return pd.MultiIndex.from_tuples(tuples, names=names)
开发者ID:mattflor,项目名称:wspec,代码行数:31,代码来源:utilities.py


示例5: update_attributes

 def update_attributes(self):
     getitem_tuple = []
     values = []
     self.signal_axes = []
     self.navigation_axes = []
     for axis in self.axes:
         if axis.slice is None:
             getitem_tuple.append(axis.index)
             values.append(axis.value)
             self.navigation_axes.append(axis)
         else:
             getitem_tuple.append(axis.slice)
             self.signal_axes.append(axis)
             
     self._getitem_tuple = getitem_tuple
     self.signal_dimension = len(self.signal_axes)
     self.navigation_dimension = len(self.navigation_axes)
     if self.navigation_dimension != 0:
         self.navigation_shape = [
             axis.size for axis in self.navigation_axes]
     else:
         self.navigation_shape = [0,]
         
     if self.signal_dimension != 0:
         self.signal_shape = [
             axis.size for axis in self.signal_axes]
     else:
         self.signal_shape = [0,]
     self.navigation_size = \
         np.cumprod(self.navigation_shape)[-1]
     self.signal_size = \
         np.cumprod(self.signal_shape)[-1]
     self._update_max_index()
开发者ID:spidermanJie,项目名称:hyperspy,代码行数:33,代码来源:axes.py


示例6: build_reflector

def build_reflector(dataset, **kwargs):
        '''
        builds reflector
        '''
        
        #some shortcuts
        vp = kwargs['model']['vp']
        rho = kwargs['model']['rho']
        R = kwargs['model']['R']
        sz = kwargs['sz']
        gz = kwargs['gz']
        sx = kwargs['sx']
        gx = kwargs['gx']
        
        numpoints = 100 #used for interpolating through the model
        for g in  gx:
                cmpx = np.floor((g + sx)/2.).astype(np.int) # nearest midpoint
                h = cmpx - sx #half offset
                #the next line extracts the non-zero reflection points at this midpoint
                rp = np.nonzero(R[cmpx,:])[0]
                #and iterates over them
                for cmpz in (rp):
                        #~ print cmpx, cmpz
                        ds = np.sqrt(cmpz**2 + (h)**2)/float(numpoints) # line step distance
                        #predefine outputs
                        amp = 1.0
                        time = 0.0

                        #traveltime from source to cdp
                        vp_down = toolbox.find_points(sx, sz, cmpx, cmpz, numpoints, vp)
                        time += 0

                        #traveltime from cdp to geophone
                        vp_up = toolbox.find_points(cmpx, cmpz, g, gz, numpoints, vp)
                        time += 0

                        #loss due to spherical divergence
                        amp *= 0

                        #transmission losses from source to cdp
                        rho_down = toolbox.find_points(sx, sz, cmpx, cmpz, numpoints, rho)
                        z0s = rho_down * vp_down
                        z1s = toolbox.roll(z0s, 1)
                        correction = np.cumprod(transmission_coefficient(z0s, z1s) )[-1] 
                        amp *= 0
                        #amplitude loss at reflection point
                        correction = R[cmpx,cmpz]
                        amp *= 0
                        #transmission loss from cdp to source
                        rho_up = toolbox.find_points(cmpx, cmpz, g, gz, numpoints, rho)
                        z0s = rho_up * vp_up
                        z1s = toolbox.roll(z0s, 1)
                        correction = np.cumprod(transmission_coefficient(z0s, z1s))[-1]
                        amp *= 0

                        #calculate coordinates
                        
                        #write out data
                        
        return 
开发者ID:stuliveshere,项目名称:Seismic-Processing-Prac1,代码行数:60,代码来源:exersize4.py


示例7: main

def main(fund_tx_file, comparision_symbol):

	fund_txn = pd.read_csv(fund_tx_file, parse_dates=[[0, 1, 2]], header=None, index_col=[0])
	fund_txn.sort_index(inplace=True)
	sorted_dates = fund_txn.index
	start_date = sorted_dates[0]
	end_date = sorted_dates[-1] + dt.timedelta(days=1)

	total_daily_rets = fund_txn.iloc[:, -1].astype('f4')
	# print total_daily_rets
	daily_ret = tsu.returnize0(total_daily_rets.copy())
	avg_daily_ret = np.mean(daily_ret)
	std_dev = np.std(daily_ret)
	sharpe = np.sqrt(252) * avg_daily_ret/std_dev
	cum_ret = total_daily_rets[-1]/total_daily_rets[0]

	comp_sym_vol, comp_sym_daily_ret, comp_sym_sharpe, comp_sym_cum_ret = optimizer.simulate(
		start_date, end_date, [comparision_symbol], [1.0])

	print("Details of the Performance of the portfolio :")
	print("Data Range : {} to {}").format(str(start_date + dt.timedelta(hours=16)), 
		str(end_date + dt.timedelta(hours=16)))

	print("Sharpe Ratio of Fund : {}").format(sharpe)
	print("Sharpe Ratio of {} : {}").format(comparision_symbol,comp_sym_sharpe)

	print("Total Return of Fund : {}").format(cum_ret)
	print("Total Return of {} : {}").format(comparision_symbol, comp_sym_cum_ret)

	print("Standard Deviation of Fund : {}").format(std_dev)
	print("Standard Deviation of {} : {}").format(comparision_symbol, comp_sym_vol)

	print("Average Daily Return of Fund : {}").format(avg_daily_ret)
	print("Average Daily Return of {} : {}").format(comparision_symbol, comp_sym_daily_ret)

	# Plot Fund vs comparing symbol
	plt.clf()
	fig = plt.figure(1)
	ax = plt.subplot(111)
	daily_ret_cummulative = np.cumprod(daily_ret + 1, axis=0)

	# Calculate daily returns for comparing symbol
	ldt_timestamps, na_price = optimizer.get_close_price_for_symbols(start_date, 
		end_date, [comparision_symbol])
	na_normalized_price = na_price / na_price[0, :]
	all_sum_daily = np.sum(na_normalized_price, 1)
	comp_sym_daily_ret = tsu.returnize0(all_sum_daily.copy())
	comp_sym_cummulative = np.cumprod(comp_sym_daily_ret + 1, axis=0)

	plt.plot(sorted_dates, daily_ret_cummulative, label='Fund', alpha=0.4)
	plt.plot(sorted_dates, comp_sym_cummulative, label=comparision_symbol)
	plt.ylabel('Cumulative Returns')
	plt.xlabel('Date')
	fig.autofmt_xdate(rotation=45)
	
	box = ax.get_position()
	ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
	# Put a legend to the right of the current axis
	ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
	plt.show()
开发者ID:sharadbhadouria,项目名称:python-examples,代码行数:60,代码来源:analyze.py


示例8: cartesian

def cartesian(nodes, order='C'):
    '''Cartesian product of a list of arrays

    Parameters:
    -----------
    nodes: (list of 1d-arrays)
    order: ('C' or 'F') order in which the product is enumerated

    Returns:
    --------
    out: (2d-array) each line corresponds to one point of the product space
    '''

    nodes = [numpy.array(e) for e in nodes]
    shapes = [e.shape[0] for e in nodes]

    n = len(nodes)
    l = numpy.prod(shapes)
    out = numpy.zeros((l, n))


    if order == 'C':
        repetitions = numpy.cumprod([1] + shapes[:-1])
    else:
        shapes.reverse()
        sh = [1] + shapes[:-1]
        repetitions = numpy.cumprod(sh)
        repetitions = repetitions.tolist()
        repetitions.reverse()

    for i in range(n):
        _repeat_1d(nodes[i], repetitions[i], out[:,i])

    return out
开发者ID:CY-Chan,项目名称:quant-econ,代码行数:34,代码来源:cartesian.py


示例9: tiCarryPlot

def tiCarryPlot(getTIresult):
    conCarry = getTIresult.ix[:,0]*getTIresult.ix[:,1]
    disCarry = getTIresult.ix[:,0]*getTIresult.ix[:,2]
    cumBetas = np.cumprod(getTIresult.ix[:,0]/100+1)-1
    cumConBetas = np.cumprod(conCarry/100+1)-1
    cumDisBetas = np.cumprod(disCarry/100+1)-1

    fig = plt.figure()

    ax1 = fig.add_subplot(311)
    ax1.set_title('Cumulative Betas')
    cumBetas.plot(style='r',label='Original Beta')
    cumConBetas.plot(style='b', label='Discrete Weights')
    cumDisBetas.plot(style='g', label='Digital Weights')
    plt.legend(loc=2)

    ax2 = fig.add_subplot(312)
    ax2.set_title('Discrete Weights')
    getTIresult.ix[:,1].plot(style='b')
    plt.ylim([0, 1.2])
    plt.yticks([0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2])

    ax3 = fig.add_subplot(313)
    ax3.set_title('Digital Weights')
    getTIresult.ix[:,2].plot(style='g')
    plt.ylim([-0.1, 1.1])
    plt.yticks([-0.1, 0.1, 0.3, 0.5, 0.7, 0.9, 1.1])

    fig.tight_layout()
    plt.show()
开发者ID:J12D,项目名称:qf-final-project,代码行数:30,代码来源:tiBeta.py


示例10: p2_strat

def p2_strat():
    data = util.load_insample()
    SO = util.extract_SO(data)
    SC = util.extract_SC(data)
    SH = util.extract_SH(data)
    SL = util.extract_SL(data)
    TVL = util.extract_TVL(data)

    RCC, avrRCC = p1_strat()
    # 1...T
    RCO = SO[1:] / SC[:-1] - 1
    cumRCO = np.cumprod(1 + np.mean(RCO, axis=1))
    powers = 1. / np.asarray(1 + np.arange(RCO.shape[0]))
    avrRCO = np.power(cumRCO, powers) - 1
    # 0...T
    ROC = SC / SO - 1
    cumROC = np.cumprod(1 + np.mean(ROC, axis=1))
    powers = 1. / np.asarray(1 + np.arange(ROC.shape[0]))
    avrROC = np.power(cumROC, powers) - 1
    # 1...T
    ROO = SO[1:] / SO[:-1] - 1
    cumROO = np.cumprod(1 + np.mean(ROO, axis=1))
    powers = 1. / np.asarray(1 + np.arange(ROO.shape[0]))
    avrROO = np.power(cumROO, powers) - 1
    # 0...T
    RVP = (1 / (4 * np.log(2))) * (np.log(SH[1:]) - np.log(SL[1:]))**2
    
    avrTVL = np.zeros(TVL.shape)
    avrRVP = np.zeros(RVP.shape)
    powers = 1. / np.asarray(1 + np.arange(TVL.shape[0]))
    avrTVL[:200, :] = np.cumsum(TVL[:200, :], axis=0)
    avrRVP[:200, :] = np.cumsum(RVP[:200, :], axis=0)
    #avrRVP[:200, :] = np.cumprod(RVP[:200, :], axis=0)
   
    print TVL.shape, RVP.shape
    for i in np.arange(200, TVL.shape[0]):
        avrTVL[i, :] = (avrTVL[i-1, :] - TVL[i-200, :] + TVL[i, :])
        if i < RVP.shape[0]:
            avrRVP[i, :] = (avrRVP[i-1, :] - RVP[i-200, :] + RVP[i, :])
        #avrRVP[i, :] = np.multiply(np.divide(avrRVP[i-1, :], RVP[i-200, :]), RVP[i, :])
    powers[200:] = 1. / 200
    #avrTVL = np.power(avrTVL, powers[:, None])
    avrTVL = np.multiply(avrTVL, powers[:, None])
    avrRVP = np.multiply(avrRVP, powers[:-1, None])
    #avrRVP = np.power(avrRVP, powers[:, None])


    #print 'RCO ', RCO[:10, :10]
    #print 'avrRCO ', avrRCO[:10]
    #print 'ROC ', ROC[:10, :10]
    #print 'avrROC ', avrROC[:10]
    #print 'ROO ', ROO[:10, :10]
    #print 'avrROO ', avrROO[:10]

    print 'RVP ', RVP[:10, :10]
    #print 'avrTVL ', avrTVL[:10, :10]
    print 'avrRVP ', avrRVP[:10, :10]

    return RCO, avrRCO, ROC, avrROC, ROO, avrROO, TVL, avrTVL, RVP, avrRVP
开发者ID:tianrui,项目名称:quant,代码行数:59,代码来源:test_utils.py


示例11: plot_backtest

def plot_backtest(config, algos, labels=None):
    """
    @:param config: config dictionary
    @:param algos: list of strings representing the name of algorithms or index of pgportfolio result
    """
    results = []
    for i, algo in enumerate(algos):
        if algo.isdigit():
            results.append(np.cumprod(_load_from_summary(algo, config)))
            logging.info("load index "+algo+" from csv file")
        else:
            logging.info("start executing "+algo)
            results.append(np.cumprod(execute_backtest(algo, config)))
            logging.info("finish executing "+algo)

    start, end = _extract_test(config)
    timestamps = np.linspace(start, end, len(results[0]))
    dates = [datetime.datetime.fromtimestamp(int(ts)-int(ts)%config["input"]["global_period"])
             for ts in timestamps]

    weeks = mdates.WeekdayLocator()
    days = mdates.DayLocator()

    rc("font", **{"family": "sans-serif", "sans-serif": ["Helvetica"],
                  "size": 8})

    """
    styles = [("-", None), ("--", None), ("", "+"), (":", None),
              ("", "o"), ("", "v"), ("", "*")]
    """
    fig, ax = plt.subplots()
    fig.set_size_inches(9, 5)
    for i, pvs in enumerate(results):
        if len(labels) > i:
            label = labels[i]
        else:
            label = NAMES[algos[i]]
        ax.semilogy(dates, pvs, linewidth=1, label=label)
        #ax.plot(dates, pvs, linewidth=1, label=label)

    plt.ylabel("portfolio value $p_t/p_0$", fontsize=12)
    plt.xlabel("time", fontsize=12)
    xfmt = mdates.DateFormatter("%m-%d %H:%M")
    ax.xaxis.set_major_locator(weeks)
    ax.xaxis.set_minor_locator(days)
    datemin = dates[0]
    datemax = dates[-1]
    ax.set_xlim(datemin, datemax)

    ax.xaxis.set_major_formatter(xfmt)
    plt.grid(True)
    plt.tight_layout()
    ax.legend(loc="upper left", prop={"size":10})
    fig.autofmt_xdate()
    plt.savefig("result.eps", bbox_inches='tight',
                pad_inches=0)
    plt.show()
开发者ID:alextavgen,项目名称:PGPortfolio,代码行数:57,代码来源:plot.py


示例12: f

 def f(self,X):
     X = reshape(X,self.input_dim)
     n = X.shape[0]
     fval = np.cumprod(np.sqrt(X),axis=1)[:,self.input_dim-1]*np.cumprod(np.sin(X),axis=1)[:,self.input_dim-1]  
     if self.sd ==0:
         noise = np.zeros(n).reshape(n,1)
     else:
         noise = np.random.normal(0,self.sd,n).reshape(n,1)
     return -fval.reshape(n,1) + noise
开发者ID:beckdaniel,项目名称:GPyOpt,代码行数:9,代码来源:experimentsNd.py


示例13: test_CumprodOp

    def test_CumprodOp(self):
        x = T.tensor3('x')
        a = np.random.random((3, 5, 2)).astype(config.floatX)

        f = theano.function([x], cumprod(x))
        assert np.allclose(np.cumprod(a), f(a))  # Test axis=None

        for axis in range(len(a.shape)):
            f = theano.function([x], cumprod(x, axis=axis))
            assert np.allclose(np.cumprod(a, axis=axis), f(a))
开发者ID:317070,项目名称:Theano,代码行数:10,代码来源:test_extra_ops.py


示例14: eqn8

 def eqn8(N, B):
     n = np.arange(N + 1, dtype=np.float64)
     # Create an array containing the factorials. scipy.special.factorial
     # requires SciPy 0.14 (#5064) therefore this is calculated by using
     # numpy.cumprod. This could be replaced by factorial again as soon as
     # older SciPy are not supported anymore but the cumprod alternative
     # might also be a bit faster.
     factorial_n = np.ones(n.shape, dtype=np.float64)
     np.cumprod(n[1:], out=factorial_n[1:])
     return 1. / (exp(-B) * np.sum(np.power(B, n) / factorial_n))
开发者ID:EdwardBetts,项目名称:astropy,代码行数:10,代码来源:funcs.py


示例15: test_cumprod

    def test_cumprod(self):

        q1 = np.array([1, 2, 6]) * u.m
        with pytest.raises(u.UnitsError) as exc:
            q1.cumprod()
        with pytest.raises(u.UnitsError) as exc:
            np.cumprod(q1)

        q2 = np.array([3, 4, 5]) * u.Unit(1)
        assert np.all(q2.cumprod() == np.array([3, 12, 60]) * u.Unit(1))
        assert np.all(np.cumprod(q2) == np.array([3, 12, 60]) * u.Unit(1))
开发者ID:Cadair,项目名称:astropy,代码行数:11,代码来源:test_quantity_array_methods.py


示例16: _generate_mult_process

def _generate_mult_process(X, mat, inits):
    """
    Return the array `M` given by `M[t+1]/M[t] = mat[X[t], X[t+1]]`
    with `M[0] = inits[X[0]]`.

    """
    M = np.empty_like(X, dtype=float)
    M[..., 0] = inits[X[..., 0]]
    M[..., 1:] = mat[X[..., :-1], X[..., 1:]]
    np.cumprod(M, axis=-1, out=M)
    return M
开发者ID:oyamad,项目名称:MultiplicativeFunctional.py,代码行数:11,代码来源:mult_functional.py


示例17: get_n_params

def get_n_params(module):
    n_param_learnable = 0
    n_param_frozen = 0

    for param in module.parameters():
        if param.requires_grad:
            n_param_learnable += np.cumprod(param.data.size())[-1]
        else:
            n_param_frozen += np.cumprod(param.data.size())[-1]

    n_param_all = n_param_learnable + n_param_frozen
    return readable_size(n_param_all), readable_size(n_param_learnable)
开发者ID:bardetadrien,项目名称:nmtpytorch,代码行数:12,代码来源:misc.py


示例18: __init__

 def __init__(self, arg, shapein=None, shapeout=None, dtype=None,
              **keywords):
     if sp.issparse(arg):
         self.__class__ = pyoperators.linear.SparseOperator
         self.__init__(arg, dtype=None, **keywords)
         return
     if not isinstance(arg, (FSCMatrix, FSRMatrix,
                             FSCBlockMatrix, FSRBlockMatrix,
                             FSCRotation2dMatrix, FSRRotation2dMatrix,
                             FSCRotation3dMatrix, FSRRotation3dMatrix)):
         raise TypeError('The input sparse matrix type is not recognised.')
     if isinstance(arg, (FSCMatrix, FSRMatrix)):
         if shapein is None:
             bshapein = keywords.pop('broadcastable_shapein',
                                     (arg.shape[1],))
         else:
             shapein = tointtuple(shapein)
             test = np.cumprod(shapein) == arg.shape[1]
             try:
                 bshapein = shapein[:ilast(test, lambda x: x) + 1]
             except ValueError:
                 bshapein = (arg.shape[1],)
         self.broadcastable_shapein = bshapein
         if shapeout is None:
             bshapeout = keywords.pop('broadcastable_shapeout',
                                      (arg.shape[0],))
         else:
             shapeout = tointtuple(shapeout)
             test = np.cumprod(shapeout) == arg.shape[0]
             try:
                 bshapeout = shapeout[:ilast(test, lambda x: x) + 1]
             except ValueError:
                 bshapeout = (arg.shape[0],)
         self.broadcastable_shapeout = bshapeout
     else:
         bs = arg.block_shape
         if shapein is None:
             if bs[1] == 1:
                 shapein = arg.shape[1]
             else:
                 shapein = arg.shape[1] // bs[1], bs[1]
         if shapeout is None:
             if bs[0] == 1:
                 shapeout = arg.shape[0]
             else:
                 shapeout = arg.shape[0] // bs[0], bs[0]
     pyoperators.linear.SparseBase.__init__(
         self, arg, dtype=dtype, shapein=shapein, shapeout=shapeout,
         **keywords)
     self.set_rule('T', self._rule_transpose)
     self.set_rule(('T', '.'), self._rule_pTp, CompositionOperator)
开发者ID:pchanial,项目名称:pysimulators,代码行数:51,代码来源:sparse.py


示例19: test_cumprod

    def test_cumprod(self):

        q1 = np.array([1, 2, 6]) * u.m
        with pytest.raises(ValueError) as exc:
            q1.cumprod()
        assert 'cannot use cumprod' in exc.value.args[0]

        with pytest.raises(ValueError) as exc:
            np.cumprod(q1)
        assert 'cannot use cumprod' in exc.value.args[0]

        q2 = np.array([3, 4, 5]) * u.Unit(1)
        assert np.all(q2.cumprod() == np.array([3, 12, 60]) * u.Unit(1))
        assert np.all(np.cumprod(q2) == np.array([3, 12, 60]) * u.Unit(1))
开发者ID:mvnnn,项目名称:astropy,代码行数:14,代码来源:test_quantity_array_methods.py


示例20: test_CumprodOp

    def test_CumprodOp(self):
        x = T.tensor3('x')
        a = np.random.random((3, 5, 2)).astype(config.floatX)

        # Test axis out of bounds
        self.assertRaises(ValueError, cumprod, x, axis=3)
        self.assertRaises(ValueError, cumprod, x, axis=-4)

        f = theano.function([x], cumprod(x))
        assert np.allclose(np.cumprod(a), f(a))  # Test axis=None

        for axis in range(-len(a.shape), len(a.shape)):
            f = theano.function([x], cumprod(x, axis=axis))
            assert np.allclose(np.cumprod(a, axis=axis), f(a))
开发者ID:Abioy,项目名称:Theano,代码行数:14,代码来源:test_extra_ops.py



注:本文中的numpy.cumprod函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.cumsum函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.cross函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap