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 "", line 1, in 
    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 "", line 1, in 
    _,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]

你可能感兴趣的:(Python,Pytorch)