.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_tutorials_1D_datasets_plot_0_1D.py: 1D{1} datasets -------------- In the following example, we illustrate how one can covert a Numpy array into a CSDM object. Start by importing the Numpy and csdmpy libraries. .. code-block:: default import matplotlib.pyplot as plt import numpy as np import csdmpy as cp Let's generate a 1D NumPy array of as our dataset. .. code-block:: default test_data = np.zeros(500) test_data[250] = 1 Create a DependentVariable object from the numpy object .. code-block:: default dv = cp.as_dependent_variable(test_data, unit="%") Create the corresponding dimensions object. Here, we create a LinearDimension object .. code-block:: default dim = cp.LinearDimension(count=500, increment="1 m") Creating the CSDM object. .. code-block:: default csdm_object = cp.CSDM(dependent_variables=[dv], dimensions=[dim]) Plot of the dataset. .. code-block:: default plt.figure(figsize=(5, 3.5)) ax = plt.gca(projection="csdm") ax.plot(csdm_object) plt.tight_layout() plt.show() .. image:: /auto_tutorials/1D_datasets/images/sphx_glr_plot_0_1D_001.png :alt: plot 0 1D :class: sphx-glr-single-img To serialize the file, use the save method. .. code-block:: default csdm_object.save("1D_1_dataset.csdf") .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.126 seconds) .. _sphx_glr_download_auto_tutorials_1D_datasets_plot_0_1D.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_0_1D.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_0_1D.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_