@@ -1252,12 +1252,48 @@ def searchsorted(self, v, side="left", sorter=None):
1252
1252
@property
1253
1253
def shape (self ):
1254
1254
"""
1255
- Lengths of axes. A tuple of numbers represents size of each dimension .
1255
+ Tuple of array dimensions .
1256
1256
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.
1259
1262
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)
1261
1297
1262
1298
"""
1263
1299
@@ -1268,16 +1304,23 @@ def shape(self, newshape):
1268
1304
"""
1269
1305
Set new lengths of axes.
1270
1306
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 .
1274
1310
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.
1276
1314
1277
- """
1315
+ For full documentation refer to :obj:`numpy.ndarray.shape`.
1278
1316
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
+ """
1281
1324
1282
1325
self ._array_obj .shape = newshape
1283
1326
0 commit comments