Skip to content

Commit da0ae2a

Browse files
committed
update description
1 parent 835094d commit da0ae2a

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

dpnp/dpnp_array.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,21 +1317,34 @@ def transpose(self, *axes):
13171317
13181318
For full documentation refer to :obj:`numpy.ndarray.transpose`.
13191319
1320+
Parameters
1321+
----------
1322+
a : {dpnp.ndarray, usm_ndarray}
1323+
Input array.
1324+
axes : None, tuple or list of ints, n ints, optional
1325+
1326+
* ``None`` or no argument: reverses the order of the axes.
1327+
* tuple or list of ints: `i` in the `j`-th place in the tuple/list
1328+
means that the array’s `i`-th axis becomes the transposed
1329+
array’s `j`-th axis.
1330+
* n ints: same as an n-tuple/n-list of the same ints (this form is
1331+
intended simply as a “convenience” alternative to the tuple form).
1332+
13201333
Returns
13211334
-------
13221335
y : dpnp.ndarray
13231336
View of the array with its axes suitably permuted.
13241337
13251338
See Also
13261339
--------
1327-
:obj:`dpnp.transpose` : Equivalent function.
1328-
:obj:`dpnp.ndarray.ndarray.T` : Array property returning the array transposed.
1329-
:obj:`dpnp.ndarray.reshape` : Give a new shape to an array without changing its data.
1340+
:obj:`dpnp.transpose` : Equivalent function.
1341+
:obj:`dpnp.ndarray.ndarray.T` : Array property returning the array transposed.
1342+
:obj:`dpnp.ndarray.reshape` : Give a new shape to an array without changing its data.
13301343
13311344
Examples
13321345
--------
1333-
>>> import dpnp as dp
1334-
>>> a = dp.array([[1, 2], [3, 4]])
1346+
>>> import dpnp as np
1347+
>>> a = np.array([[1, 2], [3, 4]])
13351348
>>> a
13361349
array([[1, 2],
13371350
[3, 4]])
@@ -1342,7 +1355,7 @@ def transpose(self, *axes):
13421355
array([[1, 3],
13431356
[2, 4]])
13441357
1345-
>>> a = dp.array([1, 2, 3, 4])
1358+
>>> a = np.array([1, 2, 3, 4])
13461359
>>> a
13471360
array([1, 2, 3, 4])
13481361
>>> a.transpose()

dpnp/dpnp_iface_manipulation.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,12 +1861,13 @@ def transpose(a, axes=None):
18611861
----------
18621862
a : {dpnp.ndarray, usm_ndarray}
18631863
Input array.
1864-
axes : tuple or list of ints, optional
1864+
axes : None, tuple or list of ints, optional
18651865
If specified, it must be a tuple or list which contains a permutation
18661866
of [0, 1, ..., N-1] where N is the number of axes of `a`.
18671867
The `i`'th axis of the returned array will correspond to the axis
1868-
numbered ``axes[i]`` of the input. If not specified, defaults to
1869-
``range(a.ndim)[::-1]``, which reverses the order of the axes.
1868+
numbered ``axes[i]`` of the input. If not specified or ``None``,
1869+
defaults to ``range(a.ndim)[::-1]``, which reverses the order of
1870+
the axes.
18701871
18711872
Returns
18721873
-------
@@ -1881,27 +1882,27 @@ def transpose(a, axes=None):
18811882
18821883
Examples
18831884
--------
1884-
>>> import dpnp as dp
1885-
>>> a = dp.array([[1, 2], [3, 4]])
1885+
>>> import dpnp as np
1886+
>>> a = np.array([[1, 2], [3, 4]])
18861887
>>> a
18871888
array([[1, 2],
18881889
[3, 4]])
1889-
>>> dp.transpose(a)
1890+
>>> np.transpose(a)
18901891
array([[1, 3],
18911892
[2, 4]])
18921893
1893-
>>> a = dp.array([1, 2, 3, 4])
1894+
>>> a = np.array([1, 2, 3, 4])
18941895
>>> a
18951896
array([1, 2, 3, 4])
1896-
>>> dp.transpose(a)
1897+
>>> np.transpose(a)
18971898
array([1, 2, 3, 4])
18981899
1899-
>>> a = dp.ones((1, 2, 3))
1900-
>>> dp.transpose(a, (1, 0, 2)).shape
1900+
>>> a = np.ones((1, 2, 3))
1901+
>>> np.transpose(a, (1, 0, 2)).shape
19011902
(2, 1, 3)
19021903
1903-
>>> a = dp.ones((2, 3, 4, 5))
1904-
>>> dp.transpose(a).shape
1904+
>>> a = np.ones((2, 3, 4, 5))
1905+
>>> np.transpose(a).shape
19051906
(5, 4, 3, 2)
19061907
19071908
"""

tests/test_manipulation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,17 @@ def test_none_axes(self, shape):
158158
na = numpy.ones(shape)
159159
da = dpnp.ones(shape)
160160

161+
assert_array_equal(numpy.transpose(na), dpnp.transpose(da))
162+
assert_array_equal(numpy.transpose(na, None), dpnp.transpose(da, None))
163+
164+
# ndarray
161165
assert_array_equal(na.transpose(), da.transpose())
162166
assert_array_equal(na.transpose(None), da.transpose(None))
167+
168+
def test_ndarray_axes_n_int(self):
169+
na = numpy.ones((1, 2, 3))
170+
da = dpnp.array(na)
171+
172+
expected = na.transpose(1, 0, 2)
173+
result = da.transpose(1, 0, 2)
174+
assert_array_equal(expected, result)

0 commit comments

Comments
 (0)