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.

Proposal: Add a todense method to matrixes.

See original GitHub issue

The method would be an identity map for numpy matrixes.

It is needed to match the interface offered by scipy. The particular situation which tripped me up was the following:

>>> # Preamble
>>> import scipy.sparse as S
>>> diagonals = [[1, 2, 3, 4], [1, 2, 3], [1, 2]]
>>> tmp = S.diags(diagonals, [0, -1, 2])

>>> tmp_lil = tmp.tolil()
>>> tmp_lil_0 = tmp_lil[0,:]
>>> tmp_lil_0[ tmp_lil_0.nonzero() ] # calling .todense() is necessary

    <1x2 sparse matrix of type '<type 'numpy.float64'>'
            with 2 stored elements in LInked List format>


>>> tmp_csc = tmp.tocsc()
>>> tmp_csc_0 = tmp_csc[0,:]
>>> tmp_csc_0[ tmp_csc_0.nonzero() ] # calling .todense() raises an exception

 matrix([[ 1.,  1.]])

I find the case to add the method compelling and do not see any obvious downsides. If it is acceptable to add it, then should it return the same object or should it return a copy?

With this information, I should be able to work on a pull request (#6066)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
WarrenWeckessercommented, Nov 18, 2021

Thanks @musically-ut, but I don’t think this enhancement request is going to be implemented.

… but I guess by the same token probably no-one cares enough about np.matrix to argue against this either 😃.

Well, it is 6 years later; I’ll argue against it! Knowing that np.matrix is destined for deprecation, it doesn’t make sense to incur the maintenance burden (answer design questions, add unit tests and run them with every PR, update documentation, etc) just to have it all go away when matrix is finally deprecated.

Given the lack of activity in this issue for the last 6 years, I think we can close this now.

0reactions
musically-utcommented, Jul 29, 2015

Actually, the fix to scipy is going to break backwards compatibility.

Hence, I am reopening this issue to see if it is worth resolving the issue at the numpy level by adding some functionality and preserving backwards compatibility.

Read more comments on GitHub >

github_iconTop Results From Across the Web

todense(), toarray() should be a module-level function and ...
I understand and agree that the kind of duck typing proposed in #5038 (adding scipy.sparse functions to numpy.matrix ) is not necessarily ...
Read more >
scipy.sparse.csc_matrix.todense — SciPy v1.9.3 Manual
A NumPy matrix object with the same shape and containing the same data represented by the sparse matrix, with the requested memory order....
Read more >
NumPy matrix to SciPy sparse matrix: What is the safest ...
Admittedly sparse matrices aren't really in my wheelhouse, but ISTM the best way forward depends on the matrix type. If you're DOK:
Read more >
NEP 13 — A mechanism for overriding Ufuncs
Here we propose adding a mechanism to override ufuncs based on the ufunc checking each of it's arguments for a __array_ufunc__ method.
Read more >
A Gentle Introduction to Sparse Matrices for Machine ...
The sparse matrix is represented using three one-dimensional arrays for the non-zero values, the extents of the rows, and the column indexes.
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