I compute an array of indices in each iteration of a loop and then I want to remove the duplicate elements and concatenate the computed array to the previous one. For example the first iteration gives me this array:
array([ 1, 6, 56, 120, 162, 170, 176, 179, 197, 204])
and the second one:
array([ 29, 31, 56, 104, 162, 170, 176, 179, 197, 204])
and so on. How could I do it?
you can concatenate arrays first with numpy.concatenate
then use np.unique
import numpy as np
a=np.array([1,6,56,120,162,170,176,179,197,204])
b=np.array([29,31,56,104,162,170,176,179,197,204])
new_array = np.unique(np.concatenate((a,b),0))
print new_array
result:
[ 1 6 29 31 56 104 120 162 170 176 179 197 204]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With