cPickle是否可以保存重塑的numpy对象引用? [英] Can cPickle save reshaped numpy object reference?

查看:120
本文介绍了cPickle是否可以保存重塑的numpy对象引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义为的类:

class A():
    def __init__():
        self.a = np.array([0,1,2,3,4,5])
        self.b = self.a.reshape((2, 3))

现在,b实际上是数组a的重构参考.如果更改a:a[0] = 10的第一个元素,则b[0, 0]也将更改为10. 但是,当我加载转储时,我使用cPickle保存此数组. a和b变为不同的数组.我想知道是否有任何方法可以使b仍然是a的引用?

now, b is in fact a reshaped reference of array a. If we change the first element of a:a[0] = 10, b[0, 0] will also change to 10. I use cPickle to save this array, however, when I load the dump. a and b become different array. I want to know whether there are any method to make b still the reference of a?

推荐答案

最新的jsonpickle预发行版本可以正确序列化numpy视图;不幸的是,泡菜没有.

the latest prerelease of jsonpickle does correctly serialize numpy views; pickle sadly does not.

这篇关于cPickle是否可以保存重塑的numpy对象引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆