I am a code and depending on what values I give to one of the variables, it works well or gives me the following error:
ValueError: shape mismatch: objects can not be broadcast to a single shape
I've been going over everything. I have located the point where I get the error and I think the why. Which brings me to something a little strange.
The line where I get the error is in the second of these two:
leng_half_mask = np.int(leng_mask / 2)
vern = tls.vernier(mask, mask_star, leng_half_mask, leng_m_star_small)
mask
and mask_star
are lists and leng_half_mask
and leng_m_star_small
are scalars.
When I run the entire program to the first line ( leng_half_mask
), the size of mask
is 370
and that of mask_star
is 368
.
When I execute the next line ( vern
) these values are modified and have a size of 372
each.
I think that by executing the line vern
and entering the function, the fact that mask
and mask_star
have different sizes generates some conflict.
But why is the size of mask
and mask_star
modified?
The tls.vernier
function that I call has the following definition. For this function to do what it should, it is necessary that A
and B
be the same size. If they are of different sizes, then add zeros to the shortest list until both lists are of equal size.:
def vernier(A, B, cA, cB):
long_A = len(A)
long_B = len(B)
dist_0cA = cA + 1
dist_0cB = cB + 1
dist_cAend = long_A - cA
dist_cBend = long_B - cB
dif_0 = dist_0cA - dist_0cB
dif_end = dist_cAend - dist_cBend
d0_abs = np.abs(dif_0)
if dif_0 < 0:
for i in range(0, d0_abs):
A.insert(0, 0)
elif dif_0 > 0:
for j in range(0, d0_abs):
B.insert(0, 0)
de_abs = np.abs(dif_end)
if dif_end < 0:
for k in range(0, de_abs):
A.append(0)
elif dif_end > 0:
for l in range(0, de_abs):
B.append(0)
long = len(A)
vernier = []
for m in range(0, long):
if A[m] == 1 or B[m] == 1:
vernier.append(1)
else:
vernier.append(0)
return vernier