3.3. Array Generate — Python
3.3.1. SetUp
3.3.2. Zeros
>>> np.zeros(shape=(2, 3)) array([[0., 0., 0.], [0., 0., 0.]])
>>> np.zeros(shape=(2, 3), dtype='int') array([[0, 0, 0], [0, 0, 0]])
3.3.3. Zeros Like
>>> a = np.array([[1, 2, 3], ... [4, 5, 6]]) >>> >>> np.zeros_like(a) array([[0, 0, 0], [0, 0, 0]])
>>> a = np.array([[1, 2, 3], ... [4, 5, 6]], dtype='float') >>> >>> np.zeros_like(a) array([[0., 0., 0.], [0., 0., 0.]])
3.3.4. Ones
>>> np.ones(shape=(3, 2)) array([[1., 1.], [1., 1.], [1., 1.]])
>>> np.ones(shape=(3, 2), dtype='int') array([[1, 1], [1, 1], [1, 1]])
3.3.5. Ones Like
>>> a = np.array([[1, 2, 3], ... [4, 5, 6]]) >>> >>> np.ones_like(a) array([[1, 1, 1], [1, 1, 1]])
>>> a = np.array([[1, 2, 3], ... [4, 5, 6]], dtype='float') >>> >>> np.ones_like(a) array([[1., 1., 1.], [1., 1., 1.]])
3.3.6. Empty
Garbage from memory
Will reuse previous if given shape was already created
>>> np.empty(shape=(3,4)) array([[ 2.31584178e+077, 1.29073692e-231, 2.96439388e-323, 0.00000000e+000], [-2.32034891e+077, 2.68678047e+154, 2.18018101e-314, 2.18022275e-314], [ 0.00000000e+000, 2.18023445e-314, 1.38338381e-322, 9.03690495e-309]])
Will reuse previous if given shape was already created:
>>> a = np.array([[1, 2, 3], ... [4, 5, 6]]) >>> >>> np.empty(shape=(2,3)) array([[1., 2., 3.], [4., 5., 6.]])
3.3.7. Empty Like
>>> a = np.array([[1, 2, 3], ... [4, 5, 6]]) >>> >>> np.empty_like(a) array([[1, 2, 3], [4, 5, 6]])
3.3.8. Full
>>> np.full(shape=(2, 3), fill_value=2) array([[2, 2, 2], [2, 2, 2]])
3.3.9. Full Like
>>> a = np.array([[1, 2, 3], ... [4, 5, 6]]) >>> >>> np.full_like(a, fill_value=2.0) array([[2, 2, 2], [2, 2, 2]])
3.3.10. Identity
>>> np.identity(2) array([[1., 0.], [0., 1.]]) >>> >>> np.identity(3) array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) >>> >>> np.identity(4, dtype='int') array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
3.3.11. Identity Like
>>> a = np.array([[1, 2, 3], ... [4, 5, 6]]) ... >>> np.identity(3, like=a) array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])
3.3.12. Recap
>>> a = np.zeros(shape=(2,3)) >>> b = np.zeros_like(a) >>> c = np.ones(shape=(2,3)) >>> d = np.ones_like(a) >>> e = np.empty(shape=(2,3)) >>> f = np.empty_like(a) >>> g = np.full(shape=(2, 2), fill_value=np.nan) >>> h = np.full_like(a, np.nan) >>> i = np.identity(4)
3.3.13. References
3.3.14. Assignments
# %% About # - Name: Numpy Generate Zeros # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray`: # - dtype: int64 # - values: 0 # - shape: 3 rows, 3 columns # - use: `np.zeros()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray`: # - dtype: int64 # - wartości: 0 # - shape: 3 wiersze, 3 kolumny # - użyj: `np.zeros()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) >>> result array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data # %% Result result = ...
# %% About # - Name: Numpy Generate ZerosLike # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray` from `DATA`: # - dtype: int64 # - values: 0 # - shape: 3 rows, 3 columns # - use: `np.zeros_like()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray` from `DATA`: # - dtype: int64 # - wartości: 0 # - shape: 3 wiersze, 3 kolumny # - użyj: `np.zeros_like()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) >>> assert result.dtype == DATA.dtype >>> assert result.itemsize == DATA.itemsize >>> assert result.shape == DATA.shape >>> assert result.strides == DATA.strides >>> result array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data DATA = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # %% Result result = ...
# %% About # - Name: Numpy Generate Ones # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray`: # - dtype: int64 # - values: 1 # - shape: 3 rows, 3 columns # - use: `np.ones()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray`: # - dtype: int64 # - wartości: 1 # - shape: 3 wiersze, 3 kolumny # - użyj: `np.ones()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) >>> result array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data # %% Result result = ...
# %% About # - Name: Numpy Generate OnesLike # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray` from `DATA`: # - dtype: int64 # - values: 1 # - shape: 3 rows, 3 columns # - use: `np.ones_like()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray` from `DATA`: # - dtype: int64 # - wartości: 1 # - shape: 3 wiersze, 3 kolumny # - użyj: `np.ones_like()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) >>> assert result.dtype == DATA.dtype >>> assert result.itemsize == DATA.itemsize >>> assert result.shape == DATA.shape >>> assert result.strides == DATA.strides >>> result array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data DATA = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # %% Result result = ...
# %% About # - Name: Numpy Generate Full # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray`: # - dtype: int64 # - values: 2 # - shape: 3 rows, 3 columns # - use: `np.full()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray`: # - dtype: int64 # - wartości: 2 # - shape: 3 wiersze, 3 kolumny # - użyj: `np.full()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) >>> result array([[2, 2, 2], [2, 2, 2], [2, 2, 2]]) """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data # %% Result result = ...
# %% About # - Name: Numpy Generate FullLike # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray` from `DATA`: # - dtype: int64 # - values: 2 # - shape: 3 rows, 3 columns # - use: `np.full_like()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray` from `DATA`: # - dtype: int64 # - wartości: 2 # - shape: 3 wiersze, 3 kolumny # - użyj: `np.full_like()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) >>> assert result.dtype == DATA.dtype >>> assert result.itemsize == DATA.itemsize >>> assert result.shape == DATA.shape >>> assert result.strides == DATA.strides >>> result array([[2, 2, 2], [2, 2, 2], [2, 2, 2]]) """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data DATA = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # %% Result result = ...
# %% About # - Name: Numpy Generate Empty # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray`: # - dtype: int64 # - values: leave default # - shape: 3 rows, 3 columns # - use: `np.empty()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray`: # - dtype: int64 # - wartości: pozostaw domyślne # - shape: 3 wiersze, 3 kolumny # - użyj: `np.empty()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data # %% Result result = ...
# %% About # - Name: Numpy Generate EmptyLike # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray` from `DATA`: # - dtype: int64 # - values: leave default # - shape: 3 rows, 3 columns # - use: `np.empty_like()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray` from `DATA`: # - dtype: int64 # - wartości: pozostaw domyślne # - shape: 3 wiersze, 3 kolumny # - użyj: `np.empty_like()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) >>> assert result.dtype == DATA.dtype >>> assert result.itemsize == DATA.itemsize >>> assert result.shape == DATA.shape >>> assert result.strides == DATA.strides """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data DATA = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # %% Result result = ...
# %% About # - Name: Numpy Generate Identity # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray`: # - dtype: int64 # - values: all zeros with ones across # - shape: 3 rows, 3 columns # - use: `np.identity()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray`: # - dtype: int64 # - wartości: same zera z jedynkami na skos # - shape: 3 wiersze, 3 kolumny # - użyj: `np.identity()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) >>> result array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data # %% Result result = ...
# %% About # - Name: Numpy Generate IdentityLike # - Difficulty: easy # - Lines: 1 # - Minutes: 2 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Define `result: np.ndarray` from `DATA`: # - dtype: int64 # - values: all zeros with ones across # - shape: 3 rows, 3 columns # - use: `np.identity()` # 2. Run doctests - all must succeed # %% Polish # 1. Zdefiniuj `result: np.ndarray` from `DATA`: # - dtype: int64 # - wartości: same zera z jedynkami na skos # - shape: 3 wiersze, 3 kolumny # - użyj: `np.identity()` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> assert sys.version_info >= (3, 9), \ 'Python has an is invalid version; expected: `3.9` or newer.' >>> assert 'result' in globals(), \ 'Variable `result` is not defined; assign result of your program to it.' >>> assert result is not Ellipsis, \ 'Variable `result` has an invalid value; assign result of your program to it.' >>> assert type(result) is np.ndarray, \ 'Variable `result` has an invalid type; expected: `np.ndarray`.' >>> assert result.dtype == np.dtype('int64') >>> assert result.itemsize == 8 >>> assert result.shape == (3, 3) >>> assert result.strides == (24, 8) >>> assert result.dtype == DATA.dtype >>> assert result.itemsize == DATA.itemsize >>> assert result.shape == DATA.shape >>> assert result.strides == DATA.strides >>> result array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports import numpy as np # %% Types result: np.ndarray # %% Data DATA = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # %% Result result = ...