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.

Units with matrix inversion

See original GitHub issue

When inverting a matrix with units using numpy.linalg.inv, the units of the inverted matrix stay the same as the input matrix. The units should also be inverted. As an example:

import numpy
import astropy.units
scale = numpy.matrix([[-1, 0], [0, 1]])*astropy.units.arcsec/astropy.units.pixel
numpy.linalg.inv(scale)

The returned value should be in units of pix/arcsec but are instead kept as arcsec/pix.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mhvkcommented, Apr 23, 2019

Thanks for reporting!

Indeed, np.matrix is not supported with units (it is a different np.ndarray subclass). Note that it is also deprecated on the numpy side, where it is suggested just to use arrays with the relevant shape.

In principle, I would hope that we can eventually support linalg with quantity arrays (with matrix shape), but we’re not there yet (needs implementation of the new __array_function__, and numpy >=1.17. So, I fear that for now you’ll just have to do things by hand…

0reactions
bsipoczcommented, Oct 24, 2019

@mhvk - I’m removing this from the milestone, but keeping the big tracking one in, just a little bit longer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are the units of an inverse matrix? - Math Stack Exchange
As you know from the cofactor formula, the entries of the inverse matrix are homogeneous ...
Read more >
What happens with a matrix unit if its inverse is taken? - Quora
The units of the inverse matrix of a matrix whose elements have physical units is: 1/units of the original matrix).
Read more >
How do units flow through matrix operations? - Stack Overflow
Answer to 4): the units of the inverse of a matrix A are given by which means that the units are the element-wise...
Read more >
Invertible matrix - Wikipedia
In linear algebra, an n-by-n square matrix A is called invertible (also nonsingular or nondegenerate), if there exists an n-by-n square matrix B...
Read more >
Definition, Formulas, Steps to Find Inverse Matrix, Examples
For example, 2 × 2, 2 × 3, 3 × 2, 3 × 3, 4 × 4 and so on. We can find...
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