Depending on your customs, flags['OWNDATA'] will do the job. In fact, there is no problem with your link. In some cases, this does not work . He will always do what he must do.
According to http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.require.html : the flag "provides an array that owns its own data."
In your "counterexample" they use the code:
print (b.flags['OWNDATA'])
But in the second case, this is the normal behavior of True.
It comes from the definition of ravel (from http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.ravel.html ).
Returns a continuous flattened array. A 1-D array containing input elements is returned. A copy is made only if necessary.
A copy is required here, so a copy is made. Thus, the variable e really owns its own data. This is not "view b", "link to b", "alias to part b". This is a real new array containing a copy of some elements of b.
So, I think this is not possible without tracking the entire data source to detect this behavior . I believe that you should create your program with this flag.
Alexis Clarembeau Jun 06 '16 at 22:12 2016-06-06 22:12
source share