[SciPy-user] unexpected array behaviour in newcore

Travis Oliphant oliphant at ee.byu.edu
Thu Nov 3 10:13:56 CST 2005

Chris Fonnesbeck wrote:

>I am trying to cast data into arrays within functions to allow for
>consistent treatment of vector and scalar variables without having to
>use switch statements. However, casting a scalar to an array under
>newcore yields some unexpected behaviour:
>>>>a = array(5)
>>>>[i for i in a]
>Why would an empty list be returned here?
Because a 0-dimensional array is not a sequence (its a scalar).  You 
could claim this should raise an error, which it should.  We are using 
the default iterator for arrays, which apparently does not raise the error.

There are functions like

atleast_1d(a)  which will convert scalars to 1-d vectors if that is what 
you are trying to do.

Using scalars as sequences in Numeric was a hack.


More information about the SciPy-user mailing list