.. 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_shape.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_shape.py: Shape manipulation ===================== .. GENERATED FROM PYTHON SOURCE LINES 4-12 .. code-block:: Python import numpy as np rg = np.random.default_rng(1) a = np.floor(10 * rg.random((3, 4))) a .. rst-class:: sphx-glr-script-out .. code-block:: none array([[5., 9., 1., 9.], [3., 4., 8., 4.], [5., 0., 7., 5.]]) .. GENERATED FROM PYTHON SOURCE LINES 14-15 return the array, flattened .. GENERATED FROM PYTHON SOURCE LINES 15-17 .. code-block:: Python a.ravel() .. rst-class:: sphx-glr-script-out .. code-block:: none array([5., 9., 1., 9., 3., 4., 8., 4., 5., 0., 7., 5.]) .. GENERATED FROM PYTHON SOURCE LINES 18-19 modified shape .. GENERATED FROM PYTHON SOURCE LINES 19-21 .. code-block:: Python a.reshape(6, 2) .. rst-class:: sphx-glr-script-out .. code-block:: none array([[5., 9.], [1., 9.], [3., 4.], [8., 4.], [5., 0.], [7., 5.]]) .. GENERATED FROM PYTHON SOURCE LINES 22-23 transpose .. GENERATED FROM PYTHON SOURCE LINES 23-25 .. code-block:: Python a.T .. rst-class:: sphx-glr-script-out .. code-block:: none array([[5., 3., 5.], [9., 4., 0.], [1., 8., 7.], [9., 4., 5.]]) .. GENERATED FROM PYTHON SOURCE LINES 26-27 .. code-block:: Python a.resize(2, 6) .. _sphx_glr_download_11_demos_python_packages_numpy_demo_shape.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_shape.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_shape.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_shape.zip `