擅长:python、mysql、java
<p>当您使用.format时,这个函数需要两个参数{}{},在您的例子中,这两个参数是latt\u const和晶格.展平(). 代码中的问题是不需要插入十个{},只需要其中两个。你知道吗</p>
<p>这应该起作用:</p>
<pre><code>import numpy as np
latt_const = 4.05
lattice = np.matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
])
print("custom {} My_Matrix {} ".format(latt_const, lattice.flatten(0)))
</code></pre>
<p>或者,如果您需要将它们分开,请尝试:</p>
<pre><code>import numpy as np
latt_const = 4.05
lattice = np.matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
])
a1 = lattice[0,:] # first row
a2 = lattice[1,:] # second row
a3 = lattice[2,:] # third row
print("custom {} a1 {} a2 {} a3 {} ".format(latt_const, a1, a2, a3))
</code></pre>