Skip to content

Invalid output shape from np.dot with matrixes (Trac #2057) #2649

Closed

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/2057 on 2012-02-17 by @pv, assigned to unknown.

http://permalink.gmane.org/gmane.comp.python.scientific.user/31095

Consider this:

import numpy as np
x = np.arange(5)
I = np.asmatrix(np.identity(5))
print np.dot(I, x).shape
# -> (1, 5)

while (5, 1) would be what is expected based on usual linear algebra rules.

It might also be a mistake to return a matrix from mixed matrix--array computations.

Activity

  1. added a commit that references this issue on Apr 4, 2013
  2. charris commented on Feb 21, 2014

    @charris
    Member

    I'm going to close this. This is a topic of endless discussion whenever 'fixing' matrices comes up. The current behaviour is that a 1D vector on the left acts like a row vector, and on the right acts like a column vector. By default, matrix([1,2,3]) is a row vector. Unfortunate, but true, and likely to stay that way until someone rethinks the matrix package.

  3. charris commented on Feb 21, 2014

    @charris
    Member

    If you need row and column vectors, you need to construct them as matrices. Maybe adding functions rowvec, colvec to construct the relevant matrices would help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions