On Mon, Jul 26, 2010 at 6:22 PM, Joshua Holbrook <josh.holbr...@gmail.com>wrote:
> On Mon, Jul 26, 2010 at 4:18 PM, Skipper Seabold <jsseab...@gmail.com> > wrote: > > On Mon, Jul 26, 2010 at 7:38 PM, Charles R Harris > > <charlesr.har...@gmail.com> wrote: > >> > >> > >> On Mon, Jul 26, 2010 at 5:05 PM, Skipper Seabold <jsseab...@gmail.com> > >> wrote: > >>> > >>> On Mon, Jul 26, 2010 at 5:48 PM, Alan G Isaac <ais...@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]])? > >>> > >> > >> Well, no ;) Matrices have determinants, scalars don't. Where are you > >> running into a problem? Is something returning a scalar where a square > array > >> would be more appropriate? > > > > No, linalg.det always returns a scalar, and I, of course, could be > > more careful and always ensure that whatever the user supplies it > > becomes a 2d array, but I don't like putting atleast_2d everywhere if > > I don't need to. I thought that the determinant of a scalar was by > > definition a scalar (e.g, google "determinant of a scalar is"), hence > > > > np.linalg.det(np.array([[2]])) > > #2.0 > > > > which should either fail or if not, then I think np.linalg.det should > > handle scalars and scalars as 1d arrays. > > > > So instead of me having to do > > > > b = np.array([2]) > > b = np.atleast_2d(b) > > np.linalg.det(b) > > #2.0 > > > > I could just do > > b = np.array([2]) > > np.linalg.det(b) > > #2.0 > > > > Regardless, doing asarray, checking if something is 2d, and then > > checking if its square seems redundant and could be replaced by an > > atleast_2d in linalg.slogdet which 1) takes a view as an array, 2) > > ensures that the we have a 2d array, and 3) handles the scalar case. > > Then we check if it's square. It doesn't really change much except > > keeping me from having to put atleast_2d's in my code. > > > > Skipper > > _______________________________________________ > > NumPy-Discussion mailing list > > NumPy-Discussion@scipy.org > > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > > > imo, the determinant of a scalar should be defined as itself, based on > the definition of the determinant. I don't have a vested interest in > linalg's behavior in this respect, though. > > And the definition of a determinant is? There are several, but the common form these days is an anti-symmetric multilinear form acting on a set of column vectors and scaled so that applying it to the columns of the identity matrix is one. In that case one would have to treat a scalar as a column vector. As a practical matter I don't have a problem with det handling scalars if it is useful to do so. Chuck
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion