Skip to content

Commit 90d79b9

Browse files
committed
add code examples
1 parent 83ceae3 commit 90d79b9

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

python/paddle/tensor/math.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8460,12 +8460,26 @@ def cartesian_prod(x: Sequence[Tensor], name: str | None = None) -> Tensor:
84608460
>>> res = paddle.cartesian_prod([a, b])
84618461
>>> print(res)
84628462
Tensor(shape=[6, 2], dtype=int32, place=Place(cpu), stop_gradient=True,
8463-
[[1, 5],
8464-
[1, 6],
8465-
[2, 5],
8466-
[2, 6],
8467-
[3, 5],
8468-
[3, 6]])
8463+
[[1, 5],
8464+
[1, 6],
8465+
[2, 5],
8466+
[2, 6],
8467+
[3, 5],
8468+
[3, 6]])
8469+
8470+
>>> c = paddle.to_tensor([7, 8, 9], dtype='float32')
8471+
>>> res = paddle.cartesian_prod([c])
8472+
>>> print(res)
8473+
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
8474+
[7., 8., 9.])
8475+
8476+
>>> d = paddle.empty([0], dtype='float64')
8477+
>>> e = paddle.to_tensor([1, 2], dtype='float64')
8478+
>>> f = paddle.to_tensor([3, 4, 5, 6, 7], dtype='float64')
8479+
>>> res = paddle.cartesian_prod([d, e, f])
8480+
>>> print(res)
8481+
Tensor(shape=[0, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
8482+
[])
84698483
"""
84708484
for tensor in x:
84718485
if len(tensor.shape) != 1:

0 commit comments

Comments
 (0)