【发布时间】:2016-02-25 10:45:18
【问题描述】:
我在 python 中有一个类:
class A:
def __init__(self):
self.obj = None
def setObj(self, npArray):
self.obj = npArray
def getObj(self):
return self.obj
在另一个 python 脚本中,我实例化了一个类 A 的对象并设置“obj”,然后在其他地方获取它
objOfA.setObj(npArray)
''' Some operations '''
objOut = objOfA.getObj()
''' More operations '''
np.append(objOut,[0.25]) ## Here np.append is used just as an example. There can be many other algebraic operations.
''' operations using objOfA '''
在上面使用objOfA的操作中,我想查看修改后的数组(附加0.25)。
在 C++ 中,使用指针或引用是很有可能的。但是我在 python 中很难做到这一点。我了解 python 如何以及何时使用对对象的引用。我的问题是尽快
objOut = objOfA.getObj()
我得到了数组的副本,但没有得到objOut 的引用。
有没有办法可以做到这一点。
提前谢谢你。
【问题讨论】:
标签: arrays python-3.x object numpy reference