.. 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() print(dates) .. rst-class:: sphx-glr-script-out .. code-block:: none ['2004-06-15T22:15:13.842235000' '1978-10-12T12:26:42.392722000' '2018-06-08T16:09:20.417184000' ... '1975-07-20T04:59:17.432479000' '1973-10-08T07:13:16.558973000' '1970-02-06T21:33:13.977613000'] .. 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([(2004, 6, 15), (1978, 10, 12), (2018, 6, 8), ..., (1975, 7, 20), (1973, 10, 8), (1970, 2, 6)], dtype=[('year', '` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex_dateutils.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex_dateutils.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_