In Matlab, P = nextpow2(A) returns the exponents for the smallest powers of two that satisfy
2^p≥|A| for each element in A.
a = [1 -2 3 -4 5 9 519];
p = nextpow2(a) returns
p = 1×7
0 1 2 2 3 4 10
Calculate the positive next powers of 2.
np2 = 2.^p
returns
np2 = 1×7
1 2 4 4 8 16 1024
I need to have the exact functionality with Python so that I can calculate this:
mag = sqrt(flow(:,:,1).^2+flow(:,:,2).^2)*scale+128;
where flow is the optical flow, meaning a velocity vector field at the size of the image, where each element shows the disparity as distance from one axes:so flow is (U1,U2) where U1.shape = (227,227) U2.shape= (227,227)
Is there a function in Python libraries? Or how I can write it the same way as it if (input is a matrix)