OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Python numpy Broadcasting problems in linalg.lstq()

  • Thread starter Thread starter Arun
  • Start date Start date
A

Arun

Guest
I am trying to implement a multi-frequency phase unwrapping algorithm using Python3 and numpy. For that, I have 7 single channel/gray scale images of shape: (1080, 1920). After stacking them along the third axes, I get (1080, 1920, 7).

I have a fixed (shift-matrix) A which is fixed for all pixels. A has the shape (7, 7). For all pixel locations, I have different intensity values (r) of shape (1, 7).

To solve them for each pixel locations by minimizing L2-norm: ||r - Au||, I can do:

Code:
# Just for example/illustration-
A = np.random.randn(7, 7)
r = np.random.randn(7, 1)

# Solved for each pixel location 
u = np.linalg.lstsq(a = A, b = r, rcond = None)

This can be implemented using 2 for loops:

Code:
for y in range(0, image_height - 1):
    for x in range(0, image_width - 1):
        # code here

this is clearly inefficient, how can I write it as efficient numpy code?
<p>I am trying to implement a multi-frequency phase unwrapping algorithm using Python3 and numpy. For that, I have 7 single channel/gray scale images of shape: (1080, 1920). After stacking them along the third axes, I get (1080, 1920, 7).</p>
<p>I have a fixed (shift-matrix) A which is fixed for all pixels. A has the shape (7, 7). For all pixel locations, I have different intensity values (r) of shape (1, 7).</p>
<p>To solve them for each pixel locations by minimizing L2-norm: ||r - Au||, I can do:</p>
<pre><code># Just for example/illustration-
A = np.random.randn(7, 7)
r = np.random.randn(7, 1)

# Solved for each pixel location
u = np.linalg.lstsq(a = A, b = r, rcond = None)
</code></pre>
<p>This can be implemented using 2 for loops:</p>
<pre><code>for y in range(0, image_height - 1):
for x in range(0, image_width - 1):
# code here
</code></pre>
<p>this is clearly inefficient, how can I write it as efficient numpy code?</p>
 

Latest posts

J
Replies
0
Views
1
jbowerbir
J
Top