- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编写一个脚本,用于处理有限元分析 (FEA) 的多个节点的计算应变/变形。对于不同的正输入扭矩有多种解决方案。我想推断这些数据并模拟负扭矩的结果。在此过程中,原始数据会发生变化。
由于我们没有直接更改任何原始值,因此我认为必须通过推断 FEA 的函数通过引用来访问它。我一直在尝试copy.deepcopy,但通过多个线程发现这不会复制类结构。在 other threads it was recommended to inherit但我正在努力使其适应我的情况。
以下代码位于包含对象同一半径上的所有节点的类内部。所有节点都位于按角度排序的 self._nodes
列表中。每个节点都有所有扭矩级别的应变。
class RadialNodeContainer:
def __init__(self, radius):
self._r = radius
self._nodes = []
def compute_negatives_radial_container(self): # ... see below
class Node:
def __init__(self, node_id, x, y, z,
strain_0nm, strain_100nm, strain_204nm, strain_369nm):
self._coordinate = Coordinate(x, y, z)
self._torque_levels = [strain_0nm, strain_100nm,
strain_204nm, strain_369nm]
def get_all_strains_complete(self):
return copy.deepcopy(self._torque_levels)
class Strain:
def __init__(self, torque_nm, exx, exy, eyy):
self._torque = torque_nm
self._exx = exx
self._exy = exy
self._eyy = eyy
导致原始数据发生不必要的更改的函数:
def compute_negatives_radial_container(self):
points_per_360deg = len(self._nodes)
jj = points_per_360deg
corresponding_node_strains = None
for ii in range(points_per_360deg):
jj -= 1
# Mistake is expected below here
corresponding_node_strains = copy.deepcopy(
self._nodes[jj].get_all_strains_complete())
for kk in range(len(corresponding_node_strains)):
torque = corresponding_node_strains[kk].get_torque_level()
if torque != 0:
exx, exy, eyy = corresponding_node_strains[kk].get_raw_strains()
calculated_negative_strain = Strain(torque_nm=-torque,
exx=exx,
exy=-exy,
eyy=eyy)
self._nodes[ii].add_torque_level(calculated_negative_strain)
我想到创建应变元素列表的深层复制
(Node -> self._torque_level
)。最初这个列表看起来像[Strain(0Nm), Strain(100Nm), ...]
。但我无法理解必须修改代码的哪些部分才能允许传递类实例的副本。
最佳答案
详细说明一下。如果我有时间,我会对此进行扩展,这正是 OP 正在寻找的内容。
我还建议对数组使用 numpy 而不是列表,因为 mumpy 更快。
class Strain:
def __init__(self, torque_nm, exx, exy, eyy):
self._torque = torque_nm
self._exx = exx
self._exy = exy
self._eyy = eyy
self._neg = False
def setNeg(self, neg):
self._neg = neg
@propery
def torque(self):
return _torque if not self._neg else -self.torque
@propery
def exx(self):
return _exx
@propery
def exy(self):
return _exy if not self._neg else -self._exy
@propery
def eyy(self):
return _eyy
关于python - 从类元素中创建 python 列表的副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55448124/
不确定我的标题措辞是否正确,但请耐心等待,所有内容都会得到解释... 我们有一组代码不是在这里发明的,它使用进程间通信(IPC 消息传递)。该方案的大致轮廓是这样的: comms.c 包含: stat
你怎么能列出所有的颠覆合并? 例如: Trunk ____9_____14____20___ \ \ \ \______\_____\___
是否有一个集合的标准 Java(1.5+)实现(即无第三方),允许我将多个集合粘合到一个集合中? 这是其工作原理的草图: final SomeCollection x = new SomeCollec
有没有办法让sql查询返回拆分行。我什至不知道怎么问。下面有'index_tag'。 select event.name, tb_ev.start_time, tb_ev.end_time from
我正在尝试使用 postgresql COPY 命令从 CSV 加载一些数据。诀窍是我想在用户标识(包含在 CSV 中)上实现 Multi-Tenancy 。加载 csv 时,是否有一种简单的方法告诉
我正在尝试使用 bash 脚本将文件复制到当前目录。 为了处理需要转义的路径,使用了一个变量,该变量被转义然后提供给 cp 命令。 cp 命令提示: usage: cp [-R [-H | -L |
我正在尝试每 20 毫秒向给定的 x 和 y 坐标添加一次 CAShapelayer。我希望形状在一秒钟内消失(就像示踪剂一样)。我创建的功能有效,形状在正确的位置创建并消失。但是我留下了额外的形状,
我是 Python 新手。我正在尝试创建一个程序来打印我通常每周手动打印的一组文档,但是我遇到了几个问题: 这是代码: import os file_list = os.listdir("C:/Pyt
我有一个大小为 10 的 ArrayList l1。我将 l1 分配给新的列表引用类型 l2。 l1 和 l2 会指向同一个 ArrayList 对象吗?或者是 ArrayList 对象的副本分配给
我这周花了一个自由职业者创建的 Mongo 4.4 PSA 副本来工作。我放弃了,从所有三台服务器上删除了完整的 mongod,然后按照 Mongo doc 从头开始安装。 .唯一的变化是在副本初
设置信息: 我有两个数据中心,每个 DC 中有 5 个节点。 我知道插入到表中的每一行都是根据使用的数据分区方案存储的;生成必要的副本并将它们存储在集群中的其他节点(根据复制策略选择节点)上。给定一行
我对 XSLT 完全陌生,所以请耐心等待。 我有两个 xml 文件,我试图使用 XSLT 将它们连接在一起。我想合并这些文件,以便第二个文件中指定的任何值覆盖第一个文件。例如 firstFile.xm
这里肯定有一个初学者问题,为什么 F# 编译器会制作不必要的 DateTimeOffset 副本,我该如何阻止它?我不记得这是个问题,但也许自从我在 F# 中使用 DateTimeOffset 以来已
我有一个用 C# 编写的 WinForms 应用程序,在将数据从 SQL 数据库导出到模板的工作表之前,它使用以下代码打开 Excel 模板。 Microsoft.Office.Interop.Exc
我从这个 post 得到的 xsl 中有这个函数 用“换行符”替换“cr” 我是这样调用它的: 我正在做文章链接,点击文本“阅读更多”
所以这可能有点难以解释...... 目前我这样做: SomeInterface xyz1 = SomeInterface.method(data); SomeInterfaceCopy xyz2 =
我有一个包含指针 p 的类型 var。我需要在另一个与 var 类型相同的变量 var1 上复制 var(通过在引号中执行 var1 "="var,因为我不知道这是否是正确的方法,请参见下文)。 在我
出于某种原因,我需要同时运行两个 xampp 副本。我在互联网上阅读了很多教程,但如果我需要运行另一个,他们最终会告诉我关闭当前的 xampp。这有可能实现吗? 最佳答案 您可以使用不同的端口同时运行
在aws中,“upload-part-copy”具有字节范围选项。如果我想将两个对象的一部分复制到云中的新对象,我可以使用“upload-part-copy”命令进行复制。 我找不到任何此类方法或机制
我有一个带栏的表 foo foo --- bar 我使用 Postgres 的 Copy 命令 COPY (select * from foo) TO 'complete_file_path' WIT
我是一名优秀的程序员,十分优秀!