源码教程 sum along column of matrix: paddle.sum api 无法使用
Created by: Joejiong
源码教程 sum along column of matrix: paddle.sum api 无法使用
自己的环境下还是在aistudio下都无法使用。 1)PaddlePaddle版本:1.7 2)CPU/GPU:cpu/gpu都不行 3)系统环境:Mac OS 10.14 4)Python: 3.7
Traceback (most recent call last): File "train_vae_linear.py", line 124, in train(model) File "train_vae_linear.py", line 63, in train loss = loss_function(recon_batch, img, mu, logvar) File "train_vae_linear.py", line 26, in loss_function BCE = paddle.sum(BCE, dim=1) AttributeError: module 'paddle' has no attribute 'sum'
doc中没有相关例子 然而在源码里面有个教程: 但是一下例子无法使用 ''' Examples: .. code-block:: python
import paddle
import paddle.fluid as fluid
# x is a Tensor variable with following elements:
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
# Each example is followed by the corresponding output tensor.
x = fluid.data(name='x', shape=[2, 4], dtype='float32')
out1 = paddle.sum(x) # [3.5]
out2 = paddle.sum(x, dim=0) # [0.3, 0.5, 1.1, 1.6]
out3 = paddle.sum(x, dim=-1) # [1.9, 1.6]
out4 = paddle.sum(x, dim=1, keep_dim=True) # [[1.9], [1.6]]
# y is a Tensor variable with shape [2, 2, 2] and elements as below:
# [[[1, 2], [3, 4]],
# [[5, 6], [7, 8]]]
# Each example is followed by the corresponding output tensor.
y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32')
out5 = paddle.sum(y, dim=[1, 2]) # [10, 26]
out6 = paddle.sum(y, dim=[0, 1]) # [16, 20]
'''