.. 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_indexing.py" .. LINE NUMBERS ARE GIVEN BELOW. .. 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_11_demos_python_packages_numpy_demo_indexing.py: Indexing, Slicing and Iterating ================================== .. GENERATED FROM PYTHON SOURCE LINES 4-12 .. code-block:: default import numpy as np # **One dimensional** a = np.arange(10)**3 a[2] .. rst-class:: sphx-glr-script-out .. code-block:: none 8 .. GENERATED FROM PYTHON SOURCE LINES 14-16 .. code-block:: default a[2:5] .. rst-class:: sphx-glr-script-out .. code-block:: none array([ 8, 27, 64], dtype=int32) .. GENERATED FROM PYTHON SOURCE LINES 17-19 .. code-block:: default a[:6:2] = 1000 .. GENERATED FROM PYTHON SOURCE LINES 20-21 reverse array .. GENERATED FROM PYTHON SOURCE LINES 21-23 .. code-block:: default a[::-1] .. rst-class:: sphx-glr-script-out .. code-block:: none array([ 729, 512, 343, 216, 125, 1000, 27, 1000, 1, 1000], dtype=int32) .. GENERATED FROM PYTHON SOURCE LINES 24-25 **Multi dimensional** .. GENERATED FROM PYTHON SOURCE LINES 25-31 .. code-block:: default def f(x, y): return 10 * x + y b = np.fromfunction(f, (5, 4), dtype=int) b .. rst-class:: sphx-glr-script-out .. code-block:: none array([[ 0, 1, 2, 3], [10, 11, 12, 13], [20, 21, 22, 23], [30, 31, 32, 33], [40, 41, 42, 43]]) .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: default b[2, 3] .. rst-class:: sphx-glr-script-out .. code-block:: none 23 .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: default b[0:5, 1] .. rst-class:: sphx-glr-script-out .. code-block:: none array([ 1, 11, 21, 31, 41]) .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: default b[:, 1] .. rst-class:: sphx-glr-script-out .. code-block:: none array([ 1, 11, 21, 31, 41]) .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: default b[1:3, :] .. rst-class:: sphx-glr-script-out .. code-block:: none array([[10, 11, 12, 13], [20, 21, 22, 23]]) .. GENERATED FROM PYTHON SOURCE LINES 44-45 .. code-block:: default b[-1] .. rst-class:: sphx-glr-script-out .. code-block:: none array([40, 41, 42, 43]) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.006 seconds) .. _sphx_glr_download_11_demos_python_packages_numpy_demo_indexing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_indexing.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_indexing.ipynb `