Skip to content

np.array_repr fails on np.matrix objects #8442

Closed

Description

@eric-wieser

Cause of #5875:

>>> np.array_repr(np.eye(2).view(np.matrix))
Traceback (most recent call last):
  File "<pyshell#52>", line 1, in <module>
    np.array_repr(np.matrix(np.eye(2)))
  File "C:\Program Files\Python 3.5\lib\site-packages\numpy\core\numeric.py", line 1807, in array_repr
    ', ', "array(")
  File "C:\Program Files\Python 3.5\lib\site-packages\numpy\core\arrayprint.py", line 447, in array2string
    separator, prefix, formatter=formatter)
  File "C:\Program Files\Python 3.5\lib\site-packages\numpy\core\arrayprint.py", line 325, in _array2string
    _summaryEdgeItems, summary_insert)[:-1]
  File "C:\Program Files\Python 3.5\lib\site-packages\numpy\core\arrayprint.py", line 519, in _formatArray
    summary_insert)
  File "C:\Program Files\Python 3.5\lib\site-packages\numpy\core\arrayprint.py", line 496, in _formatArray
    word = format_function(a[-1])
  File "C:\Program Files\Python 3.5\lib\site-packages\numpy\core\arrayprint.py", line 598, in __call__
    if isnan(x):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Spot the x[i].shape == x.shape[1:] fallacy...

Activity

  1. changed the title [-]np.array_repr fails on matrices[/-] [+]np.array_repr fails on np.matrix objects[/+] on Jan 3, 2017
  2. charris commented on Jan 3, 2017

    @charris
    Member

    At some point we should deprecate matrices and be done with them. After all, the most likely users are newbies and they should be encouraged to use Python 3.5 and later now that there is the @ operator.

  3. njsmith commented on Jan 3, 2017

    @njsmith
    Member

    We had consensus way-back-when to at least add a big warning to the docs, though I don't think it ever happened.

    At this point we might well be able to add an actual DeprecationWarning, though I don't think we can set a schedule for removing them. Maybe we should try.

  4. eric-wieser commented on Jan 3, 2017

    @eric-wieser
    MemberAuthor

    At some point we should deprecate matrices and be done with them.

    After yet another nasty matrix corner case, I had an angry search of issues in the hope that there was one titled "Finally deprecate np.matrix". I was dissapointed...

  5. eric-wieser commented on Jan 3, 2017

    @eric-wieser
    MemberAuthor

    Linked issue can probably be closed in favor of this one, anyway

  6. njsmith commented on Jan 3, 2017

    @njsmith
    Member

    Ugh, @rgommers is right, I forgot about scipy.sparse.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions