[SciPy-dev] [Numpy-discussion] Re: matrix and ravel()

Travis Oliphant oliphant at ee.byu.edu
Wed Oct 12 20:32:44 CDT 2005

Chris Barker wrote:

> Travis Oliphant wrote:
>> In particular, here are two proposals.
>> 1) current behavior
>> array (and asarray) --- returns the object itself if it is a 
>> sub-class of the array
>>                                      (or an array scalar).
>> asndarray ---  returns an actual nd array object
> -1. I expect as array to return an array. Period. That's why I use it.
>> 2) new behavior
>> array (and asarray)  always return an ndarray base-class object (or a 
>> big-nd array if the object is already one).
> +1 ...I think. What is a big-nd array?

A big-nd arrary is the parent-class of the ndarray object.  It doesn't 
have the sequence protocols or the buffer protocols and should not 
suffer from the 32-bit limitations of those protocols.   An ndarray 
inherits from the bigarray.    Eventually, when Python cleans up it's 
32-bit limitations, the bigarray will disappear. 

>> asanyarray ---  returns an nd-array or a sub-class if the object is 
>> already a sub-class.
> What about having each subclass define it's own function-- asmatrix, 
> etc? Maybe that's not general enough, but I know I use asarray because 
> I know I want a NumPy Array, and nothing else.

I guess the problem is that we are not used to coding to interfaces.   
I'm going to make the change suggested by the second point, just because 
I think it's more explicit and will make porting scipy a lot easier.  
The fact that multiplication could be redefined by the matrix which 
still passes as an array, means that lots of code can choke on matrices.  

Of course, this will have negative consequences.  It will make matrices 
much less pervasive through function calls "automatically", but it will 
be safer.  People who believe their code is safe for matrices, can use 

Now, what to do on the C-level...

Right now PyArray_FromAny(op) returns op if op is any array subclass. 

I'll probably add a flag to the requires argument that forces the result 
to be an ndarray.


More information about the Scipy-dev mailing list