[Numpy-discussion] determinant of a scalar not handled

Skipper Seabold jsseabold at gmail.com
Mon Jul 26 19:05:34 EDT 2010


On Mon, Jul 26, 2010 at 5:48 PM, Alan G Isaac <aisaac at american.edu> wrote:
> On 7/26/2010 12:45 PM, Skipper Seabold wrote:
>> Right now np.linalg.det does not handle scalars or 1d (scalar) arrays.
>
> I don't have a real opinion on changing this, but I am curious
> to know the use case, as the current behavior seems

Use case is just so that I can have less atleast_2d's in my code,
since checks are done in linalg.det anyway.

> a) correct and b) to provide an error check.
>

Isn't the determinant defined for a scalar b such that det(b) ==
det([b]) == det([[b]])?

The error check is redundant I think if the determinant is defined for
a scalar (if not then shouldn't det([[b]]) fail?).  Check if something
is 2d.  Check if something is square.  Since a square array is by
definition 2d, if you replace asarray then the check for 2d with
atleast_2d, you can handle the scalar case and then go on to check if
it's square.  Basically, it saves a tiny bit of time in det and saves
me from writing atleast_2d.

Skipper



More information about the NumPy-Discussion mailing list