Vectorized year/month/day operations with NumPy datetime64

前端 未结 3 1447
梦如初夏
梦如初夏 2021-01-05 06:06

I would like to create vectors of NumPy datetime64 objects from 1-D vectors of years, months, and days, and also go the reverse direction, that is extracting vectors of year

3条回答
  •  天涯浪人
    2021-01-05 06:57

    import numpy as np
    def compose_date(years, months=1, days=1, weeks=None, hours=None, minutes=None,
                  seconds=None, milliseconds=None, microseconds=None, nanoseconds=None):
        years = np.asarray(years) - 1970
        months = np.asarray(months) - 1
        days = np.asarray(days) - 1
        types = ('

    yields

    array(['1990-01-03', '1992-06-20', '1995-03-14', '1994-07-27'], dtype='datetime64[D]')
    

提交回复
热议问题