[Numpy-discussion] Automatic matrices

Keith Goodman kwgoodman at gmail.com
Fri Dec 15 18:44:25 CST 2006

On 12/15/06, Paulo Jose da Silva e Silva <pjssilva at ime.usp.br> wrote:

> I did not try to imply that there are some functions in numpy that
> return array when receiving matrices. What I meant is that there are
> functions in numpy that always return arrays. Hence they ask for an
> explicit conversion to matrices. Good examples is the whole numpy.random
> sub-module. So if you want a random matrix you need to type:

There are many numpy functions that will take a matrix as input but
return an array.

The nan functions (nanmin, nanmax, nanargmin, nanargmax, nansum) are an example.

The first line in these functions is

y = array(a)

which converts the matrix input into an array.

A more matrix friendly alternative would be

y = asanyarray(a)

But are there any unintended consequences of changing from array to asanyarray?

More information about the Numpy-discussion mailing list