Skip to content

Commit 5d0b0aa

Browse files
authored
Merge fe6a129 into cb31797
2 parents cb31797 + fe6a129 commit 5d0b0aa

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

dpnp/dpnp_array.py

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,12 +1252,48 @@ def searchsorted(self, v, side="left", sorter=None):
12521252
@property
12531253
def shape(self):
12541254
"""
1255-
Lengths of axes. A tuple of numbers represents size of each dimension.
1255+
Tuple of array dimensions.
12561256
1257-
Setter of this property involves reshaping without copy. If the array
1258-
cannot be reshaped without copy, it raises an exception.
1257+
The shape property is usually used to get the current shape of an array,
1258+
but may also be used to reshape the array in-place by assigning a tuple
1259+
of array dimensions to it. Unlike :obj:`dpnp.reshape`, only non-negative
1260+
values are supported to be set as new shape. Reshaping an array in-place
1261+
will fail if a copy is required.
12591262
1260-
.. seealso: :attr:`numpy.ndarray.shape`
1263+
For full documentation refer to :obj:`numpy.ndarray.shape`.
1264+
1265+
Note
1266+
----
1267+
Using :obj:`dpnp.ndarray.reshape` or :obj:`dpnp.reshape is the
1268+
preferred approach to set new shape of an array.
1269+
1270+
See Also
1271+
--------
1272+
:obj:`dpnp.shape` : Equivalent getter function.
1273+
:obj:`dpnp.reshape` : Function similar to setting `shape`.
1274+
:obj:`dpnp.ndarray.reshape` : Method similar to setting `shape`.
1275+
1276+
Examples
1277+
--------
1278+
>>> import dpnp as np
1279+
>>> x = np.array([1, 2, 3, 4])
1280+
>>> x.shape
1281+
(4,)
1282+
>>> y = np.zeros((2, 3, 4))
1283+
>>> y.shape
1284+
(2, 3, 4)
1285+
1286+
>>> y.shape = (3, 8)
1287+
>>> y
1288+
array([[[0., 0., 0., 0.],
1289+
[0., 0., 0., 0.],
1290+
[0., 0., 0., 0.]],
1291+
[[0., 0., 0., 0.],
1292+
[0., 0., 0., 0.],
1293+
[0., 0., 0., 0.]]])
1294+
>>> y.shape = (3, 6)
1295+
...
1296+
TypeError: Can not reshape array of size 24 into (3, 6)
12611297
12621298
"""
12631299

@@ -1268,16 +1304,23 @@ def shape(self, newshape):
12681304
"""
12691305
Set new lengths of axes.
12701306
1271-
A tuple of numbers represents size of each dimension.
1272-
It involves reshaping without copy. If the array cannot be reshaped without copy,
1273-
it raises an exception.
1307+
Modifies array instamcee in-place by changing its metadata about the
1308+
shape and the strides of the array, or raises `AttributeError`
1309+
exception if in-place change is not possible.
12741310
1275-
.. seealso: :attr:`numpy.ndarray.shape`
1311+
Whether the array can be reshape in-place depends on its strides. Use
1312+
:obj:`dpnp.reshape` function which always succeeds to reshape the array
1313+
by performing a copy if necessary.
12761314
1277-
"""
1315+
For full documentation refer to :obj:`numpy.ndarray.shape`.
12781316
1279-
if not isinstance(newshape, (list, tuple)):
1280-
newshape = (newshape,)
1317+
Parameters
1318+
----------
1319+
newshape : {tuple, int}
1320+
New shape. Only non-negative values are supported. The new shape
1321+
may not lead to the change in the number of elements in the array.
1322+
1323+
"""
12811324

12821325
self._array_obj.shape = newshape
12831326

dpnp/dpnp_iface_nanfunctions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ def nanmean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True):
551551
raise TypeError("If input is inexact, then out must be inexact.")
552552

553553
cnt_dtype = a.real.dtype if dtype is None else dtype
554-
# pylint: disable=invalid-unary-operand-type
555554
cnt = dpnp.sum(
556555
~mask, axis=axis, dtype=cnt_dtype, keepdims=keepdims, where=where
557556
)
@@ -1062,7 +1061,6 @@ def nanvar(
10621061

10631062
# Compute mean
10641063
var_dtype = a.real.dtype if dtype is None else dtype
1065-
# pylint: disable=invalid-unary-operand-type
10661064
cnt = dpnp.sum(
10671065
~mask, axis=axis, dtype=var_dtype, keepdims=True, where=where
10681066
)

0 commit comments

Comments
 (0)