UPDATEIFCOPY标志是否曾经为True? [英] is the UPDATEIFCOPY flag ever True?

查看:124
本文介绍了UPDATEIFCOPY标志是否曾经为True?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图加深对numpy数组的理解;特别是内存布局/所有权/共享相关方面.在这一过程中,我偶然发现了UPDATEIFCOPY标志,这听起来很有趣. 只有我从未真正看到过它. 用户只能取消设置.而且,如果您喜欢安静的话,则可以很轻松地搜索"UPDATEIFCOPY True".

I'm trying to deeper understand numpy arrays; in particular memory layout / ownership / sharing related aspects. In that endeavour I stumbled across the UPDATEIFCOPY flag which sounds intriguing. Only I've never actually seen it set. The user can only unset it. And googling "UPDATEIFCOPY True" is very relaxing if you like it quiet.

那么我如何创建一个将该标志设置为True的数组?

So how can I create an array with that flag set at True?

推荐答案

您可以设置是否使用

You can set if when you use np.nditer (example taken from NumPy source code):

>>> import numpy as np
>>> a = np.zeros((6*4+1,), dtype='i1')[1:]
>>> a.dtype = 'f4'
>>> a[:] = np.arange(6, dtype='f4')
>>> i = np.nditer(a, [], [['readwrite', 'updateifcopy', 'aligned']])
>>> print(i.operands[0].flags)
  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : True     # <--- :-)

但是我不知道这是在什么情况下真正设置的,因为如果我删除前两行,那么它将不再起作用:

However I don't know under what circumstances this is really set because if I remove the first two lines then it doesn't work anymore:

>>> import numpy as np

>>> a = np.arange(6, dtype='f4')
>>> i = np.nditer(a, [], [['readwrite', 'updateifcopy', 'aligned']])
>>> print(i.operands[0].flags)
  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False     # <--- :-(

这篇关于UPDATEIFCOPY标志是否曾经为True?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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