提问人:pg2455 提问时间:1/17/2020 最后编辑:pg2455 更新时间:1/17/2020 访问量:193
通过索引将标量值分配给 numpy 数组
Assigning scalar value to numpy array via indexing
问:
我无法将标量值分配给 numpy 数组。我想将第 2 行和第 4 列之后的所有值设置为 -10.0,在矩阵的左上角留下一个 0 块。这就像填充。A、B、C 或 D 都不适合我。我做错了什么?x[0]
x= np.zeros((4, 10, 15,1), dtype=np.float32)
x[0][2:, 4:, :] = -10 # A
x[0][2:, 4:, :] = np.array(-10, dtype=np.float32) # B
x[0, 2:, 4:, :] = -10 # C
x[0, 2:, 4:, :] = np.array(-10, dtype=np.float32) # D
x[0][0].flatten() # array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=np.float32)
更新:
这对我有用。这实际上是在填充矩阵。
x[0, 2:] = -10
x[0, :, 4:] = -10
答: 暂无答案
评论
-10
C
-10
x[0][0].flatten()