[英]How to substitute a entire line for a specific value Python
I have a 4x4 matrix B. I want to substitue the entire first line for a specific value (2):我有一个 4x4 矩阵 B。我想将整个第一行替换为特定值 (2):
B[0]=2.0
If I put this way the first line becomes [2,[....],[....],[....]]
and not [[2,2,2,2],[....],[....],[....]]
.如果我这样说,第一行变成
[2,[....],[....],[....]]
而不是[[2,2,2,2],[....],[....],[....]]
。
How can I fix that?我该如何解决?
You can do B[0] = [2 for x in range(4)]
你可以做
B[0] = [2 for x in range(4)]
you could also do B[0] = [2,2,2,2]
but if the size changes then you can put B[0] = [2 for x in range(size)]
你也可以做
B[0] = [2,2,2,2]
但如果大小发生变化,那么你可以把B[0] = [2 for x in range(size)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.