Skip to content

Commit cc4a463

Browse files
HexToStringjzhang533
authored andcommitted
update code example test=document_fix
1 parent 56a65ab commit cc4a463

File tree

1 file changed

+12
-30
lines changed
  • python/paddle/fluid/layers

1 file changed

+12
-30
lines changed

python/paddle/fluid/layers/nn.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9048,7 +9048,7 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
90489048
be changed each iteration.
90499049
offsets (list|tuple|Variable, optional): Specifies the cropping
90509050
offsets at each dimension. Its data type is int32. If a list/tuple, it's length
9051-
must be the same as the dimension size of `x`. If a Variable, it should be a 1-D
9051+
must be the same as the dimension size of `x`. If a Tensor, it should be a 1-D
90529052
Tensor. When it is a list, each element can be an integer or a Tensor of shape: [1].
90539053
If Variable contained, it is suitable for the case that the offsets may be changed
90549054
each iteration. Default: None, the offsets are 0 at each dimension.
@@ -9058,51 +9058,33 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
90589058
Returns:
90599059
Tensor: The cropped Tensor has same data type with `x`.
90609060

9061-
Raises:
9062-
TypeError: If the data type of `x` is not in: float32, float64, int32, int64.
9063-
TypeError: If `shape` is not a list, tuple or Tensor.
9064-
TypeError: If the data type of `shape` is not int32.
9065-
TypeError: If `offsets` is not None and not a list, tuple or Tensor.
9066-
TypeError: If the data type of `offsets` is not int32.
9067-
ValueError: If the element in `offsets` is less than zero.
9068-
90699061
Examples:
90709062

90719063
.. code-block:: python
90729064
:name: code-example1
90739065

90749066
import paddle
9075-
import numpy as np
9076-
np_data_x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype('int32')
9077-
x = paddle.to_tensor(np_data_x)
9067+
x = paddle.to_tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
90789068
# x.shape = [3, 3]
90799069
# x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
90809070

90819071
# shape can be a 1-D Tensor or list or tuple.
9082-
np_data_shape = np.array([2, 2]).astype('int32')
9083-
shape_tensor = paddle.to_tensor(np_data_shape)
9084-
# shape_list = [2, 2]
9085-
# shape_tuple = (2, 2)
9086-
out = paddle.crop(x, shape_tensor)
9087-
# out = paddle.crop(x, shape_list)
9088-
# out = paddle.crop(x, shape_tuple)
9089-
np_out = out.numpy()
9090-
print('out = ', np_out)
9072+
shape = paddle.to_tensor([2, 2], dtype='int32')
9073+
# shape = [2, 2]
9074+
# shape = (2, 2)
9075+
out = paddle.crop(x, shape)
90919076
# out.shape = [2, 2]
90929077
# out = [[1,2], [4,5]]
90939078

90949079
# offsets can be a 1-D Tensor or list or tuple.
9095-
np_data_offsets = np.array([0, 1]).astype('int32')
9096-
offsets_tensor = paddle.to_tensor(np_data_offsets)
9097-
# offsets_list = [1, 1]
9098-
# offsets_tuple = (0, 1)
9099-
out = paddle.crop(x, shape_tensor, offsets_tensor)
9100-
# out = paddle.crop(x, shape_tensor, offsets_list)
9101-
# out = paddle.crop(x, shape_tensor, offsets_tuple)
9102-
np_out = out.numpy()
9103-
print('out = ', np_out)
9080+
offsets = paddle.to_tensor([0, 1], dtype='int32')
9081+
# offsets = [1, 0]
9082+
# offsets = (1, 1)
9083+
out = paddle.crop(x, shape, offsets)
91049084
# out.shape = [2, 2]
9085+
# if offsets = [0, 0], out = [[1,2], [4,5]]
91059086
# if offsets = [0, 1], out = [[2,3], [5,6]]
9087+
# if offsets = [1, 0], out = [[4,5], [7,8]]
91069088
# if offsets = [1, 1], out = [[5,6], [8,9]]
91079089

91089090
"""

0 commit comments

Comments
 (0)