.. 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 ['2021-07-08T23:27:01.728351000' '1986-01-06T22:19:53.876026000' '2014-08-22T03:48:47.576783000' ... '1972-07-08T02:22:03.425555000' '2024-06-20T17:24:15.309957000' '2002-04-21T19:33:09.506837000'] .. 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([(2021, 7, 8), (1986, 1, 6), (2014, 8, 22), ..., (1972, 7, 8), (2024, 6, 20), (2002, 4, 21)], shape=(10000,), 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 `_