當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。