[Numpy-discussion] ndarray.fill and ma.array.filled
tim.hochberg at cox.net
Thu Mar 23 09:37:04 CST 2006
Fernando Perez wrote:
> Tim Hochberg wrote:
>> I don't think we're in disagreement here although I'm not sure.
>> I will add, on the subject of continuity, that I think there should
>> be a function 'ascontiguous' that parallels asarray, but assures that
>> the result is contiguous. Although this sometimes returns a copy, I
>> thinks that's OK since that's it's job. I would like to see all of
>> the implicit copying pushed into functions like asarray and
> I think we agree: something like ascontiguous() is precisely what I
> had in mind (I think that's what ravel() does today, but I'm fine if
> it gets a new name, as long as the functionality exists).
a.ravel() seems to be equivalent to reshape(a, [-1]). That is, it
returns a flattened, contiguous copy. ascontiguous(a) would be slightly
different in that it would preserves the shape of a. In fact I think it
would look a lot like:
"""ascontiguous(a) -> contiguous representation of a.
If 'a' is allready contiguous, it is returned unchanged. Otherwise,
a contiguous copy
a = asarray(a)
if not a.flags['CONTIGUOUS']:
a = array(a)
> Obviously a function like this should explicitly (docstring) say that
> it does NOT make any guarantees about whether its return value is a
> view or a copy, just that it's contiguous.
More information about the Numpy-discussion