回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有两个矩阵<code>image</code>&;<code>convolved</code>。卷积中的某些元素必须替换为字符串“x”。对应于“x”值的索引是那些出现在图像矩阵中的1。
这是我的矩阵</p>
<pre><code>import numpy as np
image = np.array([[0, 1, 0, 1, 0], [0, 0, 0, 1, 1],[0, 0, 0, 0, 0]])
convolved = np.array([[1., 1., 3., 3., 3.],[1., 1., 3., 3., 3.],[0., 0., 1., 2., 2.]])
</code></pre>
<p>这是我写的</p>
<pre><code>for m, i in enumerate(image):
for n, j in enumerate(i):
if j == 1:
#print(n,j)
convolved[m][n] = "x"
print(convolved)
</code></pre>
<p>当我运行这个时,我得到以下错误</p>
<pre><code>ValueError: could not convert string to float: 'x'
</code></pre>
<p>我想有这个输出</p>
<pre><code>array([[1., 'x', 3., 'x', 3.],
[1., 1., 3., 'x', 'x'],
[0., 0., 1., 2., 2.]])
</code></pre>
<p>有人能告诉我我做错了什么吗?
谢谢。你知道吗</p>