当前位置: 首页>>代码示例>>Python>>正文


Python stride_tricks.as_strided方法代码示例

本文整理汇总了Python中numpy.lib.stride_tricks.as_strided方法的典型用法代码示例。如果您正苦于以下问题:Python stride_tricks.as_strided方法的具体用法?Python stride_tricks.as_strided怎么用?Python stride_tricks.as_strided使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.lib.stride_tricks的用法示例。


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

示例1: handle_rolling

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def handle_rolling(agg, granularity, timestamps, values, is_aggregated,
                   references, window):
    if window > len(values):
        raise exceptions.UnAggregableTimeseries(
            references,
            "Rolling window '%d' is greater than serie length '%d'" %
            (window, len(values))
        )

    timestamps = timestamps[window - 1:]
    values = values.T
    # rigtorp.se/2011/01/01/rolling-statistics-numpy.html
    shape = values.shape[:-1] + (values.shape[-1] - window + 1, window)
    strides = values.strides + (values.strides[-1],)
    new_values = AGG_MAP[agg](as_strided(values, shape=shape, strides=strides),
                              axis=-1)
    if agg.startswith("rate:"):
        timestamps = timestamps[1:]
    return granularity, timestamps, new_values.T, is_aggregated 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:21,代码来源:operations.py

示例2: _windowed_view

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def _windowed_view(x, window_size):
    """Create a 2d windowed view of a 1d array.

    `x` must be a 1d numpy array.

    `numpy.lib.stride_tricks.as_strided` is used to create the view.
    The data is not copied.

    Example:

    >>> x = np.array([1, 2, 3, 4, 5, 6])
    >>> _windowed_view(x, 3)
    array([[1, 2, 3],
           [2, 3, 4],
           [3, 4, 5],
           [4, 5, 6]])
    """
    y = as_strided(x, shape=(x.size - window_size + 1, window_size),
                   strides=(x.strides[0], x.strides[0]))
    return y 
开发者ID:fja05680,项目名称:pinkfish,代码行数:22,代码来源:statistics.py

示例3: initialize

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def initialize(self, model):

        super(CategoricalCovStruct, self).initialize(model)

        self.nlevel = len(model.endog_values)
        self._ncut = self.nlevel - 1

        from numpy.lib.stride_tricks import as_strided
        b = np.dtype(np.int64).itemsize

        ibd = []
        for v in model.endog_li:
            jj = np.arange(0, len(v) + 1, self._ncut, dtype=np.int64)
            jj = as_strided(jj, shape=(len(jj) - 1, 2), strides=(b, b))
            ibd.append(jj)

        self.ibd = ibd 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:cov_struct.py

示例4: _strided_from_memmap

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def _strided_from_memmap(filename, dtype, mode, offset, order, shape, strides,
                         total_buffer_len):
    """Reconstruct an array view on a memory mapped file."""
    if mode == 'w+':
        # Do not zero the original data when unpickling
        mode = 'r+'

    if strides is None:
        # Simple, contiguous memmap
        return make_memmap(filename, dtype=dtype, shape=shape, mode=mode,
                           offset=offset, order=order)
    else:
        # For non-contiguous data, memmap the total enclosing buffer and then
        # extract the non-contiguous view with the stride-tricks API
        base = make_memmap(filename, dtype=dtype, shape=total_buffer_len,
                           mode=mode, offset=offset, order=order)
        return as_strided(base, shape=shape, strides=strides) 
开发者ID:flennerhag,项目名称:mlens,代码行数:19,代码来源:pool.py

示例5: sine_window

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def sine_window(X):
    """
    Apply a sinusoid window to X.

    Parameters
    ----------
    X : ndarray, shape=(n_samples, n_features)
        Input array of samples

    Returns
    -------
    X_windowed : ndarray, shape=(n_samples, n_features)
        Windowed version of X.
    """
    i = np.arange(X.shape[1])
    win = np.sin(np.pi * (i + 0.5) / X.shape[1])
    row_stride = 0
    col_stride = win.itemsize
    strided_win = as_strided(win, shape=X.shape,
                             strides=(row_stride, col_stride))
    return X * strided_win 
开发者ID:kastnerkyle,项目名称:tools,代码行数:23,代码来源:audio_tools.py

示例6: kaiserbessel_window

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def kaiserbessel_window(X, alpha=6.5):
    """
    Apply a Kaiser-Bessel window to X.

    Parameters
    ----------
    X : ndarray, shape=(n_samples, n_features)
        Input array of samples

    alpha : float, optional (default=6.5)
        Tuning parameter for Kaiser-Bessel function. alpha=6.5 should make
        perfect reconstruction possible for DCT.

    Returns
    -------
    X_windowed : ndarray, shape=(n_samples, n_features)
        Windowed version of X.
    """
    beta = np.pi * alpha
    win = sg.kaiser(X.shape[1], beta)
    row_stride = 0
    col_stride = win.itemsize
    strided_win = as_strided(win, shape=X.shape,
                             strides=(row_stride, col_stride))
    return X * strided_win 
开发者ID:kastnerkyle,项目名称:tools,代码行数:27,代码来源:audio_tools.py

示例7: stft

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def stft(sig, frame_size, overlap_fac=0.5, window=np.hanning):
    """ short time fourier transform of audio signal """
    win = window(frame_size)
    hop_size = int(frame_size - np.floor(overlap_fac * frame_size))

    # zeros at beginning (thus center of 1st window should be for sample nr. 0)
    samples = np.append(np.zeros(np.floor(frame_size / 2.0)), sig)
    # cols for windowing
    cols = np.ceil((len(samples) - frame_size) / float(hop_size)) + 1
    # zeros at end (thus samples can be fully covered by frames)
    samples = np.append(samples, np.zeros(frame_size))

    frames = stride_tricks.as_strided(
        samples,
        shape=(cols, frame_size),
        strides=(
            samples.strides[0] * hop_size,
            samples.strides[0]
        )
    ).copy()

    frames *= win

    return np.fft.rfft(frames) 
开发者ID:psobot,项目名称:SampleScanner,代码行数:26,代码来源:spectrogram.py

示例8: stft

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def stft(sig, frameSize, overlapFac=0.75, window=np.hanning):
    """ short time fourier transform of audio signal """
    win = window(frameSize)
    hopSize = int(frameSize - np.floor(overlapFac * frameSize))
    # zeros at beginning (thus center of 1st window should be for sample nr. 0)
    # samples = np.append(np.zeros(np.floor(frameSize / 2.0)), sig)
    samples = np.array(sig, dtype='float64')
    # cols for windowing
    cols = np.ceil((len(samples) - frameSize) / float(hopSize)) + 1
    # zeros at end (thus samples can be fully covered by frames)
    # samples = np.append(samples, np.zeros(frameSize))
    frames = stride_tricks.as_strided(
        samples,
        shape=(cols, frameSize),
        strides=(samples.strides[0] * hopSize, samples.strides[0])).copy()
    frames *= win
    return np.fft.rfft(frames) 
开发者ID:zhr1201,项目名称:Multi-channel-speech-extraction-using-DNN,代码行数:19,代码来源:audio_eval.py

示例9: stft

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def stft(sig, frameSize, overlapFac=0.75, window=np.hanning):
    """ short time fourier transform of audio signal """
    win = window(frameSize)
    hopSize = int(frameSize - np.floor(overlapFac * frameSize))
    # zeros at beginning (thus center of 1st window should be for sample nr. 0)
    # samples = np.append(np.zeros(np.floor(frameSize / 2.0)), sig)
    samples = np.array(sig, dtype='float64')
    # cols for windowing
    cols = np.floor((len(samples) - frameSize) / float(hopSize))
    # zeros at end (thus samples can be fully covered by frames)
    # samples = np.append(samples, np.zeros(frameSize))
    frames = stride_tricks.as_strided(
        samples,
        shape=(cols, frameSize),
        strides=(samples.strides[0] * hopSize, samples.strides[0])).copy()
    frames *= win
    return np.fft.rfft(frames) 
开发者ID:zhr1201,项目名称:Multi-channel-speech-extraction-using-DNN,代码行数:19,代码来源:spectrogram.py

示例10: stft

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def stft(sig, frameSize, overlapFac=0.75, window=np.hanning):
    """ short time fourier transform of audio signal """
    win = window(frameSize)
    hopSize = int(frameSize - np.floor(overlapFac * frameSize))
    # zeros at beginning (thus center of 1st window should be for sample nr. 0)
    # samples = np.append(np.zeros(np.floor(frameSize / 2.0)), sig)
    samples = np.array(sig, dtype='float64')
    # cols for windowing
    cols = np.ceil((len(samples) - frameSize) / float(hopSize)) + 1
    # zeros at end (thus samples can be fully covered by frames)
    # samples = np.append(samples, np.zeros(frameSize))
    frames = stride_tricks.as_strided(
        samples,
        shape=(cols, frameSize),
        strides=(samples.strides[0] * hopSize, samples.strides[0])).copy()
    frames *= win
    return np.fft.rfft(frames)


# all the definition of the flowing variable can be found
# train_net.py 
开发者ID:zhr1201,项目名称:Multi-channel-speech-extraction-using-DNN,代码行数:23,代码来源:audio_eval.py

示例11: extract_patches

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def extract_patches(arr, patch_shape=(32,32,3), extraction_step=32):
    arr_ndim = arr.ndim

    if isinstance(patch_shape, numbers.Number):
        patch_shape = tuple([patch_shape] * arr_ndim)
    if isinstance(extraction_step, numbers.Number):
        extraction_step = tuple([extraction_step] * arr_ndim)

    patch_strides = arr.strides

    slices = tuple(slice(None, None, st) for st in extraction_step)
    indexing_strides = arr[slices].strides

    patch_indices_shape = ((np.array(arr.shape) - np.array(patch_shape)) //
                           np.array(extraction_step)) + 1

    shape = tuple(list(patch_indices_shape) + list(patch_shape))
    strides = tuple(list(indexing_strides) + list(patch_strides))

    patches = as_strided(arr, shape=shape, strides=strides)
    return patches 
开发者ID:dmaniry,项目名称:deepIQA,代码行数:23,代码来源:evaluate.py

示例12: kh_make_patches

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def kh_make_patches(arr, patch_shape=2, extraction_step=1):
    arr_ndim = arr.ndim
    if isinstance(patch_shape, numbers.Number):
        patch_shape = tuple([patch_shape] * arr_ndim)
    if isinstance(extraction_step, numbers.Number):
        extraction_step = tuple([extraction_step] * arr_ndim)

    patch_strides = arr.strides

    slices = [slice(None, None, st) for st in extraction_step]
    indexing_strides = arr[slices].strides

    patch_indices_shape = (np.array(arr.shape) - np.array(patch_shape)) // np.array(extraction_step) + 1

    shape = tuple(list(patch_indices_shape) + list(patch_shape))
    strides = tuple(list(indexing_strides) + list(patch_strides))

    patches = as_strided(arr, shape=shape, strides=strides)
    return patches, shape 
开发者ID:khalooei,项目名称:ALOCC-CVPR2018,代码行数:21,代码来源:utils.py

示例13: stft

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def stft(self, sig, frameSize, overlapFac=0.5, window=np.hanning):
        win = window(frameSize)
        hopSize = int(frameSize - np.floor(overlapFac * frameSize))

        # zeros at beginning (thus center of 1st window should be for sample nr. 0)
        samples = np.append(np.zeros(np.floor(frameSize / 2.0)), sig)
        # cols for windowing
        cols = np.ceil((len(samples) - frameSize) / float(hopSize)) + 1
        # zeros at end (thus samples can be fully covered by frames)
        samples = np.append(samples, np.zeros(frameSize))

        frames = stride_tricks.as_strided(samples, shape=(cols, frameSize),
                                          strides=(samples.strides[0] * hopSize, samples.strides[0])).copy()
        frames *= win

        return np.fft.rfft(frames) 
开发者ID:HPI-DeepLearning,项目名称:crnn-lid,代码行数:18,代码来源:spectrogram2.py

示例14: stft

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def stft(self, sig):
        """
        Short term fourier transform.

        Parameters
        ----------
        sig : ndarray
            signal

        Returns
        -------
        windowed fourier transformed signal

        """
        s = np.pad(sig, (self.wlen//2, 0), 'constant')
        cols = int(np.ceil((s.shape[0] - self.wlen) / self.fshift + 1))
        s = np.pad(s, (0, self.wlen), 'constant')
        frames = as_strided(s, shape=(cols, self.wlen),
                            strides=(s.strides[0]*self.fshift,
                                     s.strides[0])).copy()
        return np.fft.rfft(frames*self.win, self.NFFT) 
开发者ID:mwv,项目名称:vad,代码行数:23,代码来源:_vad.py

示例15: stft

# 需要导入模块: from numpy.lib import stride_tricks [as 别名]
# 或者: from numpy.lib.stride_tricks import as_strided [as 别名]
def stft(sig, frameSize, overlapFac=0.5, window=np.hanning):
    win = window(frameSize)
    hopSize = int(frameSize - np.floor(overlapFac * frameSize))
    
    # zeros at beginning (thus center of 1st window should be for sample nr. 0)
    samples = np.append(np.zeros(np.floor(frameSize/2.0)), sig)    
    # cols for windowing
    cols = np.ceil( (len(samples) - frameSize) / float(hopSize)) + 1
    # zeros at end (thus samples can be fully covered by frames)
    samples = np.append(samples, np.zeros(frameSize))
    
    frames = stride_tricks.as_strided(samples, shape=(cols, frameSize), strides=(samples.strides[0]*hopSize, samples.strides[0])).copy()
    frames *= win
    
    return np.fft.rfft(frames) 
开发者ID:YerevaNN,项目名称:Spoken-language-identification,代码行数:17,代码来源:augment_data.py


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