首页 Paddle框架 帖子详情
Tensor索引和切片问题
收藏
快速回复
Paddle框架 问答深度学习 41 5
Tensor索引和切片问题
收藏
快速回复
Paddle框架 问答深度学习 41 5

按照官网示例,测试Tensor访问时,发现全是0,有大神知道怎么回事吗?

import paddle
ndim_2_Tensor = paddle.to_tensor([[0, 1, 2, 3],
[4, 5, 6, 7],
[8, 9, 10, 11]])
print("Origin Tensor:", ndim_2_Tensor.numpy())
print("First row:", ndim_2_Tensor[0].numpy())
print("First row:", ndim_2_Tensor[0, :].numpy())
print("First column:", ndim_2_Tensor[:, 0].numpy())
print("Last column:", ndim_2_Tensor[:, -1].numpy())
print("All element:", ndim_2_Tensor[:].numpy())
print("First row and second column:", ndim_2_Tensor[0, 1].numpy())

结果是:

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
runfile('G:/test/numpTest/Tensor/2d.py', wdir='G:/test/numpTest/Tensor')
Origin Tensor: [[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
W0818 09:16:43.512348 14164 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 3.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0818 09:16:43.512348 14164 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
First row: [0 0 0 0]
First row: [0 0 0 0]
First column: [0 0 0]
Last column: [0 0 0]
All element: [[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
First row and second column: [0]

0
收藏
回复
全部评论(5)
时间顺序
李长安
#2 回复于2022-08

提个issue问问吧

 

0
回复
k
kingjqk
#3 回复于2022-08
提个issue问问吧  

新手刚开始看,请问怎么提

0
回复
k
kingjqk
#4 回复于2022-08

place=paddle.CPUPlace() 指定到cpu结果就正常了

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
runfile('G:/test/numpTest/Tensor/2d.py', wdir='G:/test/numpTest/Tensor')
Origin Tensor: [[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
W0818 09:58:35.198829 8844 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 3.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0818 09:58:35.204830 8844 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
First row: [0 1 2 3]
First row: [0 1 2 3]
First column: [0 4 8]
Last column: [ 3 7 11]
All element: [[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
First row and second column: [1]

0
回复
李长安
#5 回复于2022-08

github上提issue,你是不是装的cpu版本的飞桨啊?

0
回复
k
kingjqk
#6 回复于2022-08

两台电脑,一台安装的gpu版本的,运行不正常,但是加上place=paddle.CPUPlace(),结果正常。另一台电脑装的cpu版本,运行正常。难道是我显卡的问题?但也没有报错

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户