question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

np.array_repr fails on np.matrix objects

See original GitHub issue

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…

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
charriscommented, Jan 3, 2017

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.

0reactions
njsmithcommented, Jan 3, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - How can a string representation of a NumPy array be ...
The only things that I call in my code are array , repr , eval , and all . The fact that you're...
Read more >
numpy.array_repr — NumPy v1.23 Manual
Return the string representation of an array. Parameters. arrndarray. Input array. max_line_widthint, optional. Inserts newlines if text is ...
Read more >
6 Key differences between np.ndarray and np.matrix objects
We can use np.array() function to create an ndarray object. import numpy as npA ... If we try to create a 3d matrix,...
Read more >
Difference between Numpy array and Numpy matrix
The Numpy array object in Numpy is called ndarray. We can create ndarray using numpy.array() function. It is used to convert a list,...
Read more >
Sparse matrices (scipy.sparse) — SciPy v1.9.3 Manual
This package is switching to an array interface, compatible with NumPy arrays, from the older matrix interface. We recommend that you use the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found