我有一个ndarray,其形状是(5,2)。如何将其更改为行列表,而不是列列表。 这是代码
from xml.etree import cElementTree as etree
tree = etree.parse("my_xml_file.xml")
namespaces = {"a":"http://schemas.openxmlformats.org/presentationml/2006/main"}
slidenums = tree.findall("a:fld[@type='slidenum']/a:t", namespaces)
for slidenum in slidenums:
print(slidenum.text)
然而,我想要的是
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']]
我怎么能得到它?
答案 0 :(得分:0)
您可以使用: 方法:
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())