當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.cumproduct方法代碼示例

本文整理匯總了Python中numpy.cumproduct方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.cumproduct方法的具體用法?Python numpy.cumproduct怎麽用?Python numpy.cumproduct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.cumproduct方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def __init__(self, feat_dims, upsample_scales=[4, 4, 10], compute_dims=128,
                 res_blocks=10, res_out_dims=128, pad=2):
        super().__init__()
        self.num_outputs = res_out_dims
        total_scale = np.cumproduct(upsample_scales)[-1]
        self.indent = pad * total_scale
        self.resnet = MelResNet(res_blocks, feat_dims, compute_dims, res_out_dims, pad)
        self.resnet_stretch = Stretch2d(total_scale, 1)
        self.up_layers = nn.ModuleList()
        for scale in upsample_scales:
            k_size = (1, scale * 2 + 1)
            padding = (0, scale)
            stretch = Stretch2d(scale, 1)
            conv = nn.Conv2d(1, 1, kernel_size=k_size, padding=padding, bias=False)
            conv.weight.data.fill_(1. / k_size[1])
            self.up_layers.append(stretch)
            self.up_layers.append(conv) 
開發者ID:santi-pdp,項目名稱:pase,代碼行數:19,代碼來源:modules.py

示例2: cartesian_product

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def cartesian_product(X):
    '''
    Numpy version of itertools.product or pandas.compat.product.
    Sometimes faster (for large inputs)...

    Examples
    --------
    >>> cartesian_product([list('ABC'), [1, 2]])
    [array(['A', 'A', 'B', 'B', 'C', 'C'], dtype='|S1'),
 	array([1, 2, 1, 2, 1, 2])]

    '''

    lenX = np.fromiter((len(x) for x in X), dtype=int)
    cumprodX = np.cumproduct(lenX)

    a = np.roll(cumprodX, 1)
    a[0] = 1

    b = cumprodX[-1] / cumprodX

    return [np.tile(np.repeat(x, b[i]), 
                    np.product(a[i]))
               for i, x in enumerate(X)] 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:26,代碼來源:util.py

示例3: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def __init__(self, feat_dims, upsample_scales, compute_dims,
                 res_blocks, res_out_dims, pad):
        super().__init__()
        total_scale = np.cumproduct(upsample_scales)[-1]
        self.indent = pad * total_scale
        self.resnet = MelResNet(res_blocks, feat_dims, compute_dims, res_out_dims, pad)
        self.resnet_stretch = Stretch2d(total_scale, 1)
        self.up_layers = nn.ModuleList()
        for scale in upsample_scales:
            k_size = (1, scale * 2 + 1)
            padding = (0, scale)
            stretch = Stretch2d(scale, 1)
            conv = nn.Conv2d(1, 1, kernel_size=k_size, padding=padding, bias=False)
            conv.weight.data.fill_(1. / k_size[1])
            self.up_layers.append(stretch)
            self.up_layers.append(conv) 
開發者ID:fatchord,項目名稱:WaveRNN,代碼行數:18,代碼來源:fatchord_version.py

示例4: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def __init__(self, feat_dims, upsample_scales, compute_dims, 
                 res_blocks, res_out_dims, pad) :
        super().__init__()
        total_scale = np.cumproduct(upsample_scales)[-1]
        self.indent = pad * total_scale
        self.resnet = MelResNet(res_blocks, feat_dims, compute_dims, res_out_dims)
        self.resnet_stretch = Stretch2d(total_scale, 1)
        self.up_layers = nn.ModuleList()
        for scale in upsample_scales :
            k_size = (1, scale * 2 + 1)
            padding = (0, scale)
            stretch = Stretch2d(scale, 1)
            conv = nn.Conv2d(1, 1, kernel_size=k_size, padding=padding, bias=False)
            conv.weight.data.fill_(1. / k_size[1])
            self.up_layers.append(stretch)
            self.up_layers.append(conv) 
開發者ID:G-Wang,項目名稱:WaveRNN-Pytorch,代碼行數:18,代碼來源:model.py

示例5: test_cython_group_transform_cumprod

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def test_cython_group_transform_cumprod():
    # see gh-4095
    dtype = np.float64
    pd_op, np_op = groupby.group_cumprod_float64, np.cumproduct
    _check_cython_group_transform_cumulative(pd_op, np_op, dtype) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:test_transform.py

示例6: Tuple_MI

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def Tuple_MI(Tuple, IdxLength): 
    """
    Function to return the absolution position of a multiindex when the index tuple
    and the index hierarchy and size are given.
    Example: Tuple_MI([2,7,3],[100,10,5]) = 138
    Tuple_MI is the inverse of MI_Tuple.
    """
    # First, generate the index position offset values
    A =  IdxLength[1:] +  IdxLength[:1] # Shift 1 to left
    A[-1] = 1 # Replace lowest index by 1
    A.reverse()
    IdxPosOffset = np.cumproduct(A).tolist()
    IdxPosOffset.reverse()
    Position = np.sum([a*b for a,b in zip(Tuple,IdxPosOffset)])
    return Position 
開發者ID:IndEcol,項目名稱:ODYM,代碼行數:17,代碼來源:ODYM_Functions.py

示例7: cumproduct

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def cumproduct(x, axis=0):
    return np.cumproduct(x, axis) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:4,代碼來源:functions.py

示例8: test_cumproduct

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def test_cumproduct(self):
        with pytest.raises(u.UnitsError):
            np.cumproduct(self.q) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:5,代碼來源:test_quantity_non_ufuncs.py

示例9: cartesian_product

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def cartesian_product(X):
    """
    Numpy version of itertools.product or pandas.compat.product.
    Sometimes faster (for large inputs)...

    Parameters
    ----------
    X : list-like of list-likes

    Returns
    -------
    product : list of ndarrays

    Examples
    --------
    >>> cartesian_product([list('ABC'), [1, 2]])
    [array(['A', 'A', 'B', 'B', 'C', 'C'], dtype='|S1'),
    array([1, 2, 1, 2, 1, 2])]

    See Also
    --------
    itertools.product : Cartesian product of input iterables.  Equivalent to
        nested for-loops.
    pandas.compat.product : An alias for itertools.product.
    """
    msg = "Input must be a list-like of list-likes"
    if not is_list_like(X):
        raise TypeError(msg)
    for x in X:
        if not is_list_like(x):
            raise TypeError(msg)

    if len(X) == 0:
        return []

    lenX = np.fromiter((len(x) for x in X), dtype=np.intp)
    cumprodX = np.cumproduct(lenX)

    a = np.roll(cumprodX, 1)
    a[0] = 1

    if cumprodX[-1] != 0:
        b = cumprodX[-1] / cumprodX
    else:
        # if any factor is empty, the cartesian product is empty
        b = np.zeros_like(cumprodX)

    return [np.tile(np.repeat(np.asarray(com.values_from_object(x)), b[i]),
                    np.product(a[i]))
            for i, x in enumerate(X)] 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:52,代碼來源:util.py

示例10: test_cython_group_transform_algos

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def test_cython_group_transform_algos():
    # GH 4095
    dtypes = [np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint32,
              np.uint64, np.float32, np.float64]

    ops = [(groupby.group_cumprod_float64, np.cumproduct, [np.float64]),
           (groupby.group_cumsum, np.cumsum, dtypes)]

    is_datetimelike = False
    for pd_op, np_op, dtypes in ops:
        for dtype in dtypes:
            data = np.array([[1], [2], [3], [4]], dtype=dtype)
            ans = np.zeros_like(data)
            labels = np.array([0, 0, 0, 0], dtype=np.int64)
            pd_op(ans, data, labels, is_datetimelike)
            tm.assert_numpy_array_equal(np_op(data), ans[:, 0],
                                        check_dtype=False)

    # with nans
    labels = np.array([0, 0, 0, 0, 0], dtype=np.int64)

    data = np.array([[1], [2], [3], [np.nan], [4]], dtype='float64')
    actual = np.zeros_like(data)
    actual.fill(np.nan)
    groupby.group_cumprod_float64(actual, data, labels, is_datetimelike)
    expected = np.array([1, 2, 6, np.nan, 24], dtype='float64')
    tm.assert_numpy_array_equal(actual[:, 0], expected)

    actual = np.zeros_like(data)
    actual.fill(np.nan)
    groupby.group_cumsum(actual, data, labels, is_datetimelike)
    expected = np.array([1, 3, 6, np.nan, 10], dtype='float64')
    tm.assert_numpy_array_equal(actual[:, 0], expected)

    # timedelta
    is_datetimelike = True
    data = np.array([np.timedelta64(1, 'ns')] * 5, dtype='m8[ns]')[:, None]
    actual = np.zeros_like(data, dtype='int64')
    groupby.group_cumsum(actual, data.view('int64'), labels,
                         is_datetimelike)
    expected = np.array([np.timedelta64(1, 'ns'), np.timedelta64(
        2, 'ns'), np.timedelta64(3, 'ns'), np.timedelta64(4, 'ns'),
        np.timedelta64(5, 'ns')])
    tm.assert_numpy_array_equal(actual[:, 0].view('m8[ns]'), expected) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:46,代碼來源:test_transform.py

示例11: cartesian_product

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def cartesian_product(X):
    """
    Numpy version of itertools.product or pandas.compat.product.
    Sometimes faster (for large inputs)...

    Parameters
    ----------
    X : list-like of list-likes

    Returns
    -------
    product : list of ndarrays

    Examples
    --------
    >>> cartesian_product([list('ABC'), [1, 2]])
    [array(['A', 'A', 'B', 'B', 'C', 'C'], dtype='|S1'),
    array([1, 2, 1, 2, 1, 2])]

    See also
    --------
    itertools.product : Cartesian product of input iterables.  Equivalent to
        nested for-loops.
    pandas.compat.product : An alias for itertools.product.
    """
    msg = "Input must be a list-like of list-likes"
    if not is_list_like(X):
        raise TypeError(msg)
    for x in X:
        if not is_list_like(x):
            raise TypeError(msg)

    if len(X) == 0:
        return []

    lenX = np.fromiter((len(x) for x in X), dtype=np.intp)
    cumprodX = np.cumproduct(lenX)

    a = np.roll(cumprodX, 1)
    a[0] = 1

    if cumprodX[-1] != 0:
        b = cumprodX[-1] / cumprodX
    else:
        # if any factor is empty, the cartesian product is empty
        b = np.zeros_like(cumprodX)

    return [np.tile(np.repeat(np.asarray(com._values_from_object(x)), b[i]),
                    np.product(a[i]))
            for i, x in enumerate(X)] 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:52,代碼來源:util.py

示例12: test_cython_group_transform_algos

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import cumproduct [as 別名]
def test_cython_group_transform_algos(self):
        # GH 4095
        dtypes = [np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint32,
                  np.uint64, np.float32, np.float64]

        ops = [(groupby.group_cumprod_float64, np.cumproduct, [np.float64]),
               (groupby.group_cumsum, np.cumsum, dtypes)]

        is_datetimelike = False
        for pd_op, np_op, dtypes in ops:
            for dtype in dtypes:
                data = np.array([[1], [2], [3], [4]], dtype=dtype)
                ans = np.zeros_like(data)
                labels = np.array([0, 0, 0, 0], dtype=np.int64)
                pd_op(ans, data, labels, is_datetimelike)
                tm.assert_numpy_array_equal(np_op(data), ans[:, 0],
                                            check_dtype=False)

        # with nans
        labels = np.array([0, 0, 0, 0, 0], dtype=np.int64)

        data = np.array([[1], [2], [3], [np.nan], [4]], dtype='float64')
        actual = np.zeros_like(data)
        actual.fill(np.nan)
        groupby.group_cumprod_float64(actual, data, labels, is_datetimelike)
        expected = np.array([1, 2, 6, np.nan, 24], dtype='float64')
        tm.assert_numpy_array_equal(actual[:, 0], expected)

        actual = np.zeros_like(data)
        actual.fill(np.nan)
        groupby.group_cumsum(actual, data, labels, is_datetimelike)
        expected = np.array([1, 3, 6, np.nan, 10], dtype='float64')
        tm.assert_numpy_array_equal(actual[:, 0], expected)

        # timedelta
        is_datetimelike = True
        data = np.array([np.timedelta64(1, 'ns')] * 5, dtype='m8[ns]')[:, None]
        actual = np.zeros_like(data, dtype='int64')
        groupby.group_cumsum(actual, data.view('int64'), labels,
                             is_datetimelike)
        expected = np.array([np.timedelta64(1, 'ns'), np.timedelta64(
            2, 'ns'), np.timedelta64(3, 'ns'), np.timedelta64(4, 'ns'),
            np.timedelta64(5, 'ns')])
        tm.assert_numpy_array_equal(actual[:, 0].view('m8[ns]'), expected) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:46,代碼來源:test_transform.py


注:本文中的numpy.cumproduct方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。