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


Python numpy.datetime_data方法代碼示例

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


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

示例1: _validate_date_like_dtype

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import datetime_data [as 別名]
def _validate_date_like_dtype(dtype):
    """
    Check whether the dtype is a date-like dtype. Raises an error if invalid.

    Parameters
    ----------
    dtype : dtype, type
        The dtype to check.

    Raises
    ------
    TypeError : The dtype could not be casted to a date-like dtype.
    ValueError : The dtype is an illegal date-like dtype (e.g. the
                 the frequency provided is too specific)
    """

    try:
        typ = np.datetime_data(dtype)[0]
    except ValueError as e:
        raise TypeError('{error}'.format(error=e))
    if typ != 'generic' and typ != 'ns':
        msg = '{name!r} is too specific of a frequency, try passing {type!r}'
        raise ValueError(msg.format(name=dtype.name, type=dtype.type.__name__)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:common.py

示例2: _datetime_metadata_str

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import datetime_data [as 別名]
def _datetime_metadata_str(dtype):
    # TODO: this duplicates the C append_metastr_to_string
    unit, count = np.datetime_data(dtype)
    if unit == 'generic':
        return ''
    elif count == 1:
        return '[{}]'.format(unit)
    else:
        return '[{}{}]'.format(count, unit) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:_dtype.py

示例3: test_basic

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import datetime_data [as 別名]
def test_basic(self):
        a = np.array(['1980-03-23'], dtype=np.datetime64)
        assert_equal(np.datetime_data(a.dtype), ('D', 1)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:5,代碼來源:test_datetime.py

示例4: fourier_model_mat

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import datetime_data [as 別名]
def fourier_model_mat(datetimes: np.ndarray,
                      K: int,
                      period: Union[np.timedelta64, str],
                      output_fmt: str = 'float64') -> np.ndarray:
    """
    :param datetimes: An array of datetimes.
    :param K: The expansion integer.
    :param period: Either a np.timedelta64, or one of {'weekly','yearly','daily'}
    :param start_datetime: A np.datetime64 on which to consider the season-start; useful for aligning (e.g) weekly
    seasons to start on Monday, or daily seasons to start on a particular hour. Default is first monday after epoch.
    :param output_fmt: A numpy dtype, or 'dataframe' to output a dataframe.
    :return: A numpy array (or dataframe) with the expanded fourier series.
    """
    # parse period:
    name = 'fourier'
    if isinstance(period, str):
        name = period
        if period == 'weekly':
            period = np.timedelta64(7, 'D')
        elif period == 'yearly':
            period = np.timedelta64(int(365.25 * 24), 'h')
        elif period == 'daily':
            period = np.timedelta64(24, 'h')
        else:
            raise ValueError("Unrecognized `period`.")

    period_int = period.view('int64')
    dt_helper = DateTimeHelper(dt_unit=np.datetime_data(period)[0])
    time = dt_helper.validate_datetimes(datetimes).view('int64')

    output_dataframe = (output_fmt.lower() == 'dataframe')
    if output_dataframe:
        output_fmt = 'float64'

    # fourier matrix:
    out_shape = tuple(datetimes.shape) + (K * 2,)
    out = np.empty(out_shape, dtype=output_fmt)
    columns = []
    for idx in range(K):
        k = idx + 1
        for is_cos in range(2):
            val = 2. * np.pi * k * time / period_int
            out[..., idx * 2 + is_cos] = np.sin(val) if is_cos == 0 else np.cos(val)
            columns.append(f"{name}_K{k}_{'cos' if is_cos else 'sin'}")

    if output_dataframe:
        if len(out_shape) > 2:
            raise ValueError("Cannot output dataframe when input is 2+D array.")
        from pandas import DataFrame
        out = DataFrame(out, columns=columns)

    return out 
開發者ID:strongio,項目名稱:torch-kalman,代碼行數:54,代碼來源:features.py


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