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]

猜你喜欢

转载自blog.csdn.net/weixin_41797117/article/details/80068957