.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\python_packages\numpy\demo_stacking.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_11_demos_python_packages_numpy_demo_stacking.py: Stacking arrays ================== .. GENERATED FROM PYTHON SOURCE LINES 4-13 .. code-block:: Python import numpy as np rg = np.random.default_rng(1) a = np.floor(10 * rg.random((2, 2))) b = np.floor(10 * rg.random((2, 2))) np.vstack((a, b)) .. rst-class:: sphx-glr-script-out .. code-block:: none array([[5., 9.], [1., 9.], [3., 4.], [8., 4.]]) .. GENERATED FROM PYTHON SOURCE LINES 15-17 .. code-block:: Python np.hstack((a, b)) .. rst-class:: sphx-glr-script-out .. code-block:: none array([[5., 9., 3., 4.], [1., 9., 8., 4.]]) .. GENERATED FROM PYTHON SOURCE LINES 18-20 .. code-block:: Python np.column_stack((a, b)) .. rst-class:: sphx-glr-script-out .. code-block:: none array([[5., 9., 3., 4.], [1., 9., 8., 4.]]) .. GENERATED FROM PYTHON SOURCE LINES 21-23 .. code-block:: Python a[:, np.newaxis] .. rst-class:: sphx-glr-script-out .. code-block:: none array([[[5., 9.]], [[1., 9.]]]) .. GENERATED FROM PYTHON SOURCE LINES 24-26 .. code-block:: Python np.column_stack((a[:, np.newaxis], b[:, np.newaxis])) .. rst-class:: sphx-glr-script-out .. code-block:: none array([[[5., 9.], [3., 4.]], [[1., 9.], [8., 4.]]]) .. GENERATED FROM PYTHON SOURCE LINES 27-29 .. code-block:: Python np.column_stack is np.hstack .. rst-class:: sphx-glr-script-out .. code-block:: none False .. GENERATED FROM PYTHON SOURCE LINES 30-31 .. code-block:: Python np.row_stack is np.vstack .. rst-class:: sphx-glr-script-out .. code-block:: none True .. _sphx_glr_download_11_demos_python_packages_numpy_demo_stacking.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_stacking.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_stacking.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_stacking.zip `