[Numpy-discussion] array, asarray as contiguous and friends
Tim Hochberg
tim.hochberg at cox.net
Fri Mar 24 13:40:04 CST 2006
Travis Oliphant wrote:
> Tim Hochberg wrote:
>
>>>
>>>
>>> Please see the transpose example above.
>>>
>>>> If you combine this with one other simplification: array() always
>>>> copies, we end up with a nice thin interface:
>>>> # Create a new array in 'order' order. Defaults to "C" order.
>>>> array(object, dtype=None, order="C"|"FORTRAN")
>>>
>>>
> I like the order flag. It's a relatively easy switch and one we
> should make right now. I don't mind string constants either in this
> case.
Great!
> Removing the copy flag will break a lot of code because it's been
> around for a long time. This is also not an "easy thing" to add to
> convertcode.py though I suppose 90% of the cases could be found.
I kinda figured on that. But I figured I'd propose my favorite and see
what came of it.
> We would also have to re-write asarray to be an additional C-function
> to make it not copy but make array copy.
I thought so too at first, but I don't this is is so. Untested, and can
could probably be cleaned up some:
def asarray(obj, order=None):
if type(obj) == ndarray:
if order:
if not obj.flags.contiguous:
return array(obj, order)
if order == "C" and obj.flags.fortran:
return array(obj, order)
if order == "FORTRAN" and not obj.flags.fortran:
return array(obj, order)
return obj
else:
if order:
return array(obj, order)
else:
return array(obj)
For asanyarray, simply replace the type test with an isinstance test.
> So, for now I'm not as enthused about that idea.
Yeah. Without backward compatibility constraints I'm convinced that it's
the right thing to do, but I realize there is a need to balance making
the transistion manageable with making things "perfect".
-tim
More information about the Numpy-discussion
mailing list