Python中在numpy和torch.tensor形式下对max函数用法的实验

a=np.array([[1,2,3,4],[5,6,7,8],[-1,-4,-6,-9],[-1,3,-7,4]])

c,d=a.max(1)
Traceback (most recent call last):

  File "<ipython-input-11-1f6dcaa960e0>", line 1, in <module>
    c,d=a.max(1)

ValueError: too many values to unpack (expected 2)




a.max(1)
Out[12]: array([ 4,  8, -1,  4])

a.max(0)
Out[13]: array([5, 6, 7, 8])

_,c=a.max(1)
Traceback (most recent call last):

  File "<ipython-input-14-aa0718d3a962>", line 1, in <module>
    _,c=a.max(1)

ValueError: too many values to unpack (expected 2)




a=torch.from_numpy(a)

a
Out[16]: 

 1  2  3  4
 5  6  7  8
-1 -4 -6 -9
-1  3 -7  4
[torch.IntTensor of size 4x4]

_,c=a.max(1)

_
Out[18]: 

 4
 8
-1
 4
[torch.IntTensor of size 4]

c
Out[19]: 

 3
 3
 0
 3
[torch.LongTensor of size 4]

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值