NumPy resize method
From the documentation (emphasis mine):
The purpose of the reference count check is to make sure you do not use this array as a buffer for another Python object and then reallocate the memory. However, reference counts can increase in other ways so if you are sure that you have not shared the memory for this array with another Python object, then you may safely set
refcheck
toFalse
.
Your "peek", unlike print
, does not decrement the reference count afterwards. This is because, in the interpreter, the result of the last computation is assigned to _
. Try:
print(_) # shows arraya.resize((3, 2), refcheck=False) # works
Alternatively, if you do any other computation (e.g. just 1 + 2
) in-between, this will dereference your array from _
.