# Winner Take All mechanism using lateral inhibition

**URL:** <https://brian.discourse.group/t/winner-take-all-mechanism-using-lateral-inhibition/609>\
**Category:** Support\
**Tags:** synapses\
**Created:** [16 February 2022 01:05 UTC](https://brian.discourse.group/t/winner-take-all-mechanism-using-lateral-inhibition/609 "2022-02-16T01:05:59Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [23 February 2022 10:12 UTC](https://brian.discourse.group/t/winner-take-all-mechanism-using-lateral-inhibition/609/6 "2022-02-23T10:12:25Z")

</div>

Hi. As I mentioned in my earlier post, using a custom function to deal with this is a bit complicated, using a `network_operation` would be easier. You are getting the error message because the model code is translated into Cython code, and you only provide a Python implementation for your function. But again, this complicates things here, since functions are meant to do calculations for a single neuron/synapse, not across neurons as your `np.argmax` here. Your second variant cannot run, since code you provide in the strings is not Python code, it is “Brian code” in a special syntax (a subset of Python syntax) that later gets translated into Cython code.

Here’s a simple example (without the inhibition etc.), that shows how you can use a `network_operation` to restrict spiking to a single neuron in each time step:

```nohighlight
tau_m = 50*ms
neurons = NeuronGroup(2, '''dv/dt = -v/tau_m : 1
                            is_winner : boolean''',
                      threshold='v > 1 and is_winner',
                      reset='v=0')
@network_operation(when='before_thresholds')
def determine_winner():
    neurons.is_winner[:] = (neurons.i[:] == np.argmax(neurons.v_[:]))

```

---

_[View the full topic](https://brian.discourse.group/t/winner-take-all-mechanism-using-lateral-inhibition/609)._
