[Numpy-discussion] who owns the data?
Wed Nov 30 14:30:47 CST 2011
just a basic question (since I haven't looked at this in some time)
I'm creating a structured array in a function. However, I want to
return the array with just a simple dtype
uni = uni.view(dt).reshape(-1, ncols)
the returned uni has owndata=False. Who owns the data, since the
underlying, original array went out of scope?
uni = np.asarray(uni, dt).reshape(-1, ncols)
looks obvious but raises exception
uni.dtype = dt
this works and uni owns the data. I'm only worried whether assigning
to dtype directly is not a dangerous thing to do.
array([0, 0, 0, 1, 1, 0, 1, 1])
>>> u.dtype = np.dtype("float")
array([ 0.00000000e+000, 2.12199579e-314, 4.94065646e-324,
adding a safety check:
for t in uni.dtype.fields.values():
assert (t == dt)
maybe I shouldn't care if nobody owns the data.
More information about the NumPy-Discussion