python - AttributeError:“列表”对象没有属性“副本”。在 3.6 中工作,在 3.7 中失败
问题描述
代码摘录:
toMatrix = [0.0] * NumBoth #Establish dimensions
for i in range(NumBoth):
toMatrix [i] = [0.0] * NumBoth
for indx in iter(range(NumSvcDep,NumBoth)):
toMatrix [indx][indx] = 1.0
print(type(toMatrix),type(fromMatrix))
fromMatrix = toMatrix.copy()
如果上下文很重要,我将矩阵设置为“0”,但对角线的一部分设置为“1”。虽然我很想听到更好的方法来做到这一点,但我的主要问题是复制。这在 V3.6 上运行,但在 v3.7 上失败。我很确定代码没有更改,但已经有一段时间了。
解决方案
Deep copy of list works a little different:
fromMatrix = toMatrix[:]
should solve your error, Alternatively, you can do:
fromMatrix = list(toMatrix)
推荐阅读
- autodesk-forge - 模型伪造查看器中缺少 Autodesk.AEC.ModelData
- javascript - 使用 NodeJS 将 MediaRecorder 块合并到单个视频文件中
- powershell - Powershell MS Teams 'New-Team' 崩溃
- java - 如何在 IntelliJ 中使用库的代码而不是 jar 文件
- sql - 在 MS-ACCESS SQL 中添加要查询的行
- apache - 如何使用htaccess根据不同的条件进行重定向?
- javascript - 如何在 Vue3 组合 API 上使用 Vue2 插件?
- image - 显示来自共享点列表的图像
- maven - Groovy 依赖管理
- java - 如何在 Docker 中使用 OAuth2 运行 Micronaut 应用程序