Skip to content

Commit 85a014a

Browse files
committed
Leverage dpnp.ndindex on numpy class
1 parent d06277f commit 85a014a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

dpnp/dpnp_iface_indexing.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"indices",
6868
"ix_",
6969
"mask_indices",
70+
"ndindex",
7071
"nonzero",
7172
"place",
7273
"put",
@@ -1059,6 +1060,57 @@ def mask_indices(
10591060
return nonzero(a != 0)
10601061

10611062

1063+
# pylint: disable=invalid-name
1064+
ndindex = numpy.ndindex
1065+
ndindex.__doc__ = """
1066+
An N-dimensional iterator object to index arrays.
1067+
1068+
Given the shape of an array, an `ndindex` instance iterates over the
1069+
N-dimensional index of the array. At each iteration a tuple of indices is
1070+
returned, the last dimension is iterated over first.
1071+
1072+
For full documentation refer to :obj:`numpy.ndindex`.
1073+
1074+
Parameters
1075+
----------
1076+
shape : ints, or a single tuple of ints
1077+
The size of each dimension of the array can be passed as individual
1078+
parameters or as the elements of a tuple.
1079+
1080+
See Also
1081+
--------
1082+
:obj:`dpnp.ndenumerate` : Multidimensional index iterator.
1083+
:obj:`dpnp.flatiter` : Flat iterator object to iterate over arrays.
1084+
1085+
Examples
1086+
--------
1087+
>>> import dpnp as np
1088+
1089+
Dimensions as individual arguments
1090+
1091+
>>> for index in np.ndindex(3, 2, 1):
1092+
... print(index)
1093+
(0, 0, 0)
1094+
(0, 1, 0)
1095+
(1, 0, 0)
1096+
(1, 1, 0)
1097+
(2, 0, 0)
1098+
(2, 1, 0)
1099+
1100+
Same dimensions - but in a tuple ``(3, 2, 1)``
1101+
1102+
>>> for index in np.ndindex((3, 2, 1)):
1103+
... print(index)
1104+
(0, 0, 0)
1105+
(0, 1, 0)
1106+
(1, 0, 0)
1107+
(1, 1, 0)
1108+
(2, 0, 0)
1109+
(2, 1, 0)
1110+
1111+
"""
1112+
1113+
10621114
def nonzero(a):
10631115
"""
10641116
Return the indices of the elements that are non-zero.

0 commit comments

Comments
 (0)