我的程序基本上读取了一个输入文件,从该文件生成一个lxml.etree,而不是例如我向etree添加一个节点,然后我想将它打印回一个文件.所以要把它写回我使用的文件:
et.write('Documents\Write.xml', pretty_print=True)
Run Code Online (Sandbox Code Playgroud)
我的输出是:
<Variable Name="one" RefID="two"><Component Type="three"><Value>four</Value></Component></Variable>
Run Code Online (Sandbox Code Playgroud)
虽然我喜欢这样的东西:
<Variable Name="one" RefID="two">
<Component Type="three">
<Value>four</Value>
</Component>
</Variable>
Run Code Online (Sandbox Code Playgroud)
我哪里弄错了?我尝试了很多解决方案,但似乎没有工作(beautifulsoup,整洁,解析器...)
我需要在numpy.array中找到一个向量.例如,我有一个名为e的np.array,我想找到e中的向量[1,2](意思是我想在矩阵中有向量的索引)但显然我的程序看到了向量甚至何时不存在:
我用来构建e的代码如下:
import numpy as np
faces = np.array([[1,2,3,4],[5,6,2,1],[6,7,3,2],[7,8,4,3],[8,5,1,4],[8,7,6,5]])
e = np.zeros([6,4,2])
for k in range(len(faces)):
a = [faces[k][0], faces[k][1]]
b = [faces[k][1], faces[k][2]]
c = [faces[k][2], faces[k][3]]
d = [faces[k][3], faces[k][0]]
e[k] = np.array([a,b,c,d])
print('e: %s' %e)
Run Code Online (Sandbox Code Playgroud)
任何线索如何解决这个问题?
我需要从3D numpy数组中删除一些行.例如:
a = [[1,2,3]
[4,5,6]
[7,8,9]
[9,8,7]
[6,5,4]
[3,2,1]]
Run Code Online (Sandbox Code Playgroud)
我想删除矩阵的两个页面的第三行,以获得类似的东西:
a = [[1,2,3]
[4,5,6]
[9,8,7]
[6,5,4]]
Run Code Online (Sandbox Code Playgroud)
我试过了
a = numpy.delete(a, 2, axis=0)
Run Code Online (Sandbox Code Playgroud)
但我无法获得我所需要的东西.