当前位置: 首页>>代码示例>>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;未经允许,请勿转载。