将numpy ndarray从列列表转换为行列表



我有一个ndarray,它的形状是(5,2)。如何将其更改为行列表,而不是列列表。这是代码

poly
array([['610.0', '1150.0'],
   ['675', '1150'],
   ['675', '1215'],
   ['610', '1215'],
   ['610', '1150']], 
  dtype='|S32')
shape(poly)
 (5,2)
poly.tolist()
 [['610.0', '1150.0'],
 ['675', '1150'],
 ['675', '1215'],
 ['610', '1215'],
 ['610', '1150']]

然而,我想要的是

 [['610.0', '1150.0'],['675', '1150'],['675', '1215'],['610', '1215'],['610', '1150']]

我怎么能得到它?

您可以使用:方法:

ndarray.T
ndarray.transpose()

在您的情况下:

poly.T

poly.transpose()

使用此:

import numpy as np
poly=np.array([['610.0', '1150.0'],
   ['675', '1150'],
   ['675', '1215'],
   ['610', '1215'],
   ['610', '1150']], 
  dtype='|S32')
print("poly", poly)
print()
#print(poly.shape())
print("poly.tolist()", poly.tolist())
#print(poly.T)
print()
print("poly.transpose()", poly.transpose())

相关内容

  • 没有找到相关文章

最新更新