.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/ex_dateutils.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_ex_dateutils.py: ******************** Numpy date utilities ******************** This library provides utility functions to perform conversions and get information about numpy dates quickly. .. GENERATED FROM PYTHON SOURCE LINES 10-29 .. code-block:: Python import datetime import random import numpy import pyinterp def make_date(samples=10000): """Generates random dates.""" epoch = datetime.datetime(1970, 1, 1) delta = datetime.datetime.now() - datetime.datetime(1970, 1, 1) pydates = [epoch + random.random() * delta for _ in range(samples)] npdates = numpy.array(pydates).astype('datetime64[ns]') return npdates .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python dates = make_date() dates .. rst-class:: sphx-glr-script-out .. code-block:: none array(['2017-06-13T07:13:05.648487000', '1978-06-25T11:48:48.603000000', '1998-01-25T14:05:15.643924000', ..., '2003-12-29T04:12:31.934470000', '2007-06-19T07:28:11.876077000', '1987-01-27T19:55:41.243390000'], dtype='datetime64[ns]') .. GENERATED FROM PYTHON SOURCE LINES 34-36 Get the date part as a structured numpy array of three fields: ``year``, ``month`` and ``day``: .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: Python pyinterp.dateutils.date(dates) .. rst-class:: sphx-glr-script-out .. code-block:: none array([(2017, 6, 13), (1978, 6, 25), (1998, 1, 25), ..., (2003, 12, 29), (2007, 6, 19), (1987, 1, 27)], dtype=[('year', '` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex_dateutils.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_