[Numpy-discussion] array, asarray as contiguous and friends
Colin J. Williams
cjw at sympatico.ca
Fri Mar 24 06:50:04 EST 2006
Tim Hochberg wrote:
> Colin J. Williams wrote:
>
>> Tim Hochberg wrote:
>>
>>>
>>>
>>> I was just looking at the interface for array and asarray to see
>>> what other stuff should go in the interface of the hypothetical
>>> ascontiguous. There's 'dtype', which I knew about, and 'fortran',
>>> which I didn't, but which makes sense. However, there's also
>>> 'ndmin'. First off, it's not described in docstring for asarray, but
>>> I was able to find it in the docstring for array without a problem.
>>> Second, is it really necessary? It seems to be useful in an awfully
>>> narrow set of circumstances, particularly since when you are padding
>>> axes not everyone wants to pad to the left.
>>>
>>> It would seem to be more useful to ditch the ndmin and have some
>>> sort of paddims function that was more full featured (padding to
>>> either the left or the right at a minimum). I'm not entirely sure
>>> what the best interface to such a beast would look like, but a
>>> simple tactic would be to just provide leftpaddims and rightpaddims.
>>>
>>> If it's not allready clear by now (;), I prefer several narrow
>>> interfaces to one broad one.
>>>
>>> -tim
>>>
>>
>>
>>
>> What does ascontiguous do that copy doesn't?
>
>
> What it doesn't do is always copy the argument. Just like asarray, it
> returns it unchanged if it's contiguous.
Fair enough. I guess that, for some array a, "b= ascontiguous(a)"
saves a few keystrokes as compared
with "b= a if a.flags.contiguous else a.copy()". The intent of the
latter is clearer and probably burns fewer cycles.
numarray has an iscontiguous method, which is a bit simpler than
concerning the Python user with flags.
>
>> In numarray, transpose created a discontiguous array. copy() made
>> the array contiguous. Is there sufficient benefit to justify another
>> method?
>
>
> I was proposing a function, not a method. The array object has plenty
> of methods already.
Since the function would only operate on ArrayType instances, would it
not be better as a method?
Colin W.
>
> -tim
>
>>
>> Colin W.
>>
>>
>
>
More information about the NumPy-Discussion
mailing list