I’m trying to make sure two sets of synapses, e.g. S_e2i and S_i2e, are mutually exclusive. In another word, the “target” and “source” of S_e2i will not show up as the “source” and “target” in the S_i2e.

What was done is to use Brian command to generate connections for each sets, then loop over each element of source and target to remove duplicated. The step of removing the duplicate is very slow. Is there a way to speed it up? The following is the snippet of the example.

Thanks

```
#spatial connection e2i
self.S_e2i[i].connect(p='exp(-((x_pre-x_post)**2 + (y_pre-y_post)**2)/(2*(sigma)**2))', skip_if_invalid=True, namespace={'sigma':self.sigma_e2i})
self.S_e2i[i].max_delay = self.max_delay
self.S_e2i[i].delay = 'rand()* max_delay'
# get the connection matrix of this S_e2i[i]
matrix_S_e2i = np.zeros([len(self.exci_neurons[i]), len(self.inhib_neurons[i])], dtype=bool)
matrix_S_e2i[self.S_e2i[i].i[:], self.S_e2i[i].j[:]] = True
source_e2i, target_e2i = matrix_S_e2i.nonzero()
#spatial connection i2e
self.S_i2e_temp[i].connect(p='exp(-((x_pre-x_post)**2 + (y_pre-y_post)**2)/(2*(sigma)**2))', skip_if_invalid=True, namespace={'sigma':self.sigma_i2e})
self.S_i2e_temp[i].active = False # it's only a step-stone for the S_i2e and should be inactive
# get the connection matrix of this S_i2e_temp[i] which include S_e2i connection between the same neurons pairs
matrix_S_i2e = np.zeros([len(self.inhib_neurons[i]), len(self.exci_neurons[i])], dtype=bool)
matrix_S_i2e[self.S_i2e_temp[i].i[:], self.S_i2e_temp[i].j[:]] = True
ss, tt = matrix_S_i2e.nonzero()
# now make sure e->i and i->e connection are mutually exclusive, i.e. for one connection from e->i, there's no i->e connection from the same meuron ID
print("..... removing overlapping connection between e2i and i2e")
source_i2e = []
target_i2e = []
for idx_pre, idx_post in zip(ss, tt):
if (idx_pre, idx_post) not in zip(target_e2i, source_e2i): # note: the source and target of e2i and i2e are opposite
source_i2e.append(idx_pre)
target_i2e.append(idx_post)
```