@@ -1284,12 +1284,45 @@ def searchsorted(self, v, side="left", sorter=None):
1284
1284
@property
1285
1285
def shape (self ):
1286
1286
"""
1287
- Lengths of axes. A tuple of numbers represents size of each dimension .
1287
+ Tuple of array dimensions .
1288
1288
1289
- Setter of this property involves reshaping without copy. If the array
1290
- cannot be reshaped without copy, it raises an exception.
1289
+ The shape property is usually used to get the current shape of an array,
1290
+ but may also be used to reshape the array in-place by assigning a tuple
1291
+ of array dimensions to it. Unlike :obj:`dpnp.reshape`, only non-negative
1292
+ values are supported to be set as new shape. Reshaping an array in-place
1293
+ will fail if a copy is required.
1291
1294
1292
- .. seealso: :attr:`numpy.ndarray.shape`
1295
+ For full documentation refer to :obj:`numpy.ndarray.shape`.
1296
+
1297
+ Note
1298
+ ----
1299
+ Using :obj:`dpnp.ndarray.reshape` or :obj:`dpnp.reshape` is the
1300
+ preferred approach to set new shape of an array.
1301
+
1302
+ See Also
1303
+ --------
1304
+ :obj:`dpnp.shape` : Equivalent getter function.
1305
+ :obj:`dpnp.reshape` : Function similar to setting `shape`.
1306
+ :obj:`dpnp.ndarray.reshape` : Method similar to setting `shape`.
1307
+
1308
+ Examples
1309
+ --------
1310
+ >>> import dpnp as np
1311
+ >>> x = np.array([1, 2, 3, 4])
1312
+ >>> x.shape
1313
+ (4,)
1314
+ >>> y = np.zeros((2, 3, 4))
1315
+ >>> y.shape
1316
+ (2, 3, 4)
1317
+
1318
+ >>> y.shape = (3, 8)
1319
+ >>> y
1320
+ array([[ 0., 0., 0., 0., 0., 0., 0., 0.],
1321
+ [ 0., 0., 0., 0., 0., 0., 0., 0.],
1322
+ [ 0., 0., 0., 0., 0., 0., 0., 0.]])
1323
+ >>> y.shape = (3, 6)
1324
+ ...
1325
+ TypeError: Can not reshape array of size 24 into (3, 6)
1293
1326
1294
1327
"""
1295
1328
@@ -1300,16 +1333,23 @@ def shape(self, newshape):
1300
1333
"""
1301
1334
Set new lengths of axes.
1302
1335
1303
- A tuple of numbers represents size of each dimension.
1304
- It involves reshaping without copy. If the array cannot be reshaped without copy,
1305
- it raises an exception .
1336
+ Modifies array instance in-place by changing its metadata about the
1337
+ shape and the strides of the array, or raises `AttributeError`
1338
+ exception if in-place change is not possible .
1306
1339
1307
- .. seealso: :attr:`numpy.ndarray.shape`
1340
+ Whether the array can be reshape in-place depends on its strides. Use
1341
+ :obj:`dpnp.reshape` function which always succeeds to reshape the array
1342
+ by performing a copy if necessary.
1308
1343
1309
- """
1344
+ For full documentation refer to :obj:`numpy.ndarray.shape`.
1310
1345
1311
- if not isinstance (newshape , (list , tuple )):
1312
- newshape = (newshape ,)
1346
+ Parameters
1347
+ ----------
1348
+ newshape : {tuple, int}
1349
+ New shape. Only non-negative values are supported. The new shape
1350
+ may not lead to the change in the number of elements in the array.
1351
+
1352
+ """
1313
1353
1314
1354
self ._array_obj .shape = newshape
1315
1355
0 commit comments