New to Python, and have been learning about arrays. I am stuck with a simple enough problem and need a solution. I have two arrays:
a = [2.0, 5.1, 6.2, 7.9, 23.0] # always increasing
b = [5.1, 5.5, 5.7, 6.2, 00.0] # also always increasing
and I want the resultant array to be:
c = [0.0, 5.1, 6.2, 0.0, 0.0] # 5.5, 5.7, 00.0 from 'b' were dropped and rearranged such that position of equivalent elements as in 'a' are maintained
I have compared both 'a' & 'b' using Numpy as in:
y = np.isclose(a, b)
print y
# [False False False False False]
(Alternately,) I also tried something like this, which isn't the right way (I think):
c = np.zeros(len(a))
for i in range (len(a)):
for j in range (len(a)):
err = abs(a[i]-b[j])
if err == 0.0 or err < abs(1):
print (err, a[i], b[j], i, j)
else:
print (err, a[i], b[j], i, j)
How do I proceed from here towards obtaining 'c'?
y = np.isclose(a, b, atol=0.05).atol=0.5gives[False True True False False]which iscbool-wise.aat position ofTruevalues? Or is there a better way of doing it?a=[5,6,7]; b=[0,0,5]givec=[5,0,0]? (Your comment in your 2nd code snippet is not clear to me.)