python - 当你重塑它时,numpy 数组的 getrefcount 发生了什么
问题描述
重塑 np.array 时,内存块中发生了什么?
一旦我做 sys.gerefcount。我得到 print(sys.getrefcount(foo2)) 和 print(sys.getrefcount(foo1)) 的不同结果
foo1 = np.array([1,2,3])
foo2 = foo1.reshape(3,1)
print(sys.getrefcount(foo1))
print(sys.getrefcount(foo2))
解决方案
我假设:
print(sys.getrefcount(foo1))
2
print(sys.getrefcount(foo2))
3
根据文档:
sys.getrefcount(object)
Return the reference count of the object. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an argument to getrefcount().
使用您的命令:foo2 = foo1.reshape(3,1)
您引用对象 1,因此总共导致 3 个引用
推荐阅读
- linux - VSCode:无法建立与“localhost”的连接(已解决)
- amazon-web-services - 通过 Gitlab CI-CD 管道登录 aws
- sql - SQL查询仅显示今天的数据?
- reactjs - axios 删除功能只是从表中删除最后一个用户,而不是我点击的那个
- python - Python Pandas Dataframe 减前行和列
- informix - INFORMIX 错误:SERIAL 列可能未更新
- python - 如何在 Pandas 中可视化缺失值模式
- python - 按特定顺序写入列表中的每个元素
- python - 在 Pyspark 中导入 Hudi 模块
- jsonata - 使用 jsonata 从数组的过滤结果投影