这可能是一个愚蠢的问题,但是说我想从下到上构建一个程序,如下所示:
class Atom(object):
def __init__(self):
'''
Constructor
'''
def atom(self, foo, bar):
#...with foo and bar being arrays of atom Params of lengths m & n
"Do what atoms do"
return atom_out
...我可以将我的实例放入字典中:
class Molecule(Atom):
def __init__(self):
def structure(self, a, b):
#a = 2D array of size (num_of_atoms, m); 'foo' Params for each atom
#b = 2D array of size (num_of_atoms, n); 'bar' Params for each atom
unit = self.atom()
fake_array = {"atom1": unit(a[0], b[0]),
"atom2": unit(a[1], b[1]),
: : :
: : :}
def chemicalBonds(self, this, that, theother):
: : :
: : :
我的问题是,有没有办法用 numpy 数组来做到这一点,这样“ real_array
”中的每个元素都将是一个实例——即函数atom
的单个计算的输出atom
?我可以将其扩展到可以对大型和输出class Water(molecule):
执行快速 numpy 操作,因此需要数组......或者是我以错误的方式解决这个问题吗?structure
chemicalBonds
另外,如果我走在正确的轨道上,如果您想提出有关如何构建这样的“分层程序”的任何提示,我将不胜感激,因为我不确定我是否正确地执行了上述操作并且最近发现我不知道我在做什么。
提前致谢。