# Description of problem

So I am trying to make an Izkevich neuron model with a Tsodokys model for the synapses, but I need to set the Izkevich Neuron’s current equal to the sum of the synaptic currents plus their external currents but I get a dimension mismatch error with

``````x = getattr(s, f'I_{ng_pre.name}')
print(x)
setattr(ng_post, f'Isyn_{ng_post.name}', x)
``````

# Thank you for your help in advance. Minimal code to reproduce problem

``````def _get_Synaptic_Params():
return synaptic_params
#manyTargets will fill this dictionary up with values for each of the variables
#  so that way they can be carried into the synapseModel equation

uxhwModel = '''
du_syn/dt = -u_syn/tau_u: 1 (clock-driven)
dx/dt = ((1-x) * tau_xInv): 1 (clock-driven)
w : volt (constant)
du_plus/dt = 0 * (1/ms) : 1 (clock-driven)
'''
#'''dIsyn/dt = -Isyn * tsInv + (h * x * w * (1/mV)) * (mamp/ms) : amp (clock-driven)'''
def manyTargets(ng_pre_name):
return f'dI_{ng_pre_name}/dt =  -I_{ng_pre_name} * tsInv + (u_plus * x * w * (1/mV)) * (mamp/ms) : amp (clock-driven)'
def group_synapse():
num_synapse = []
for (ng_pre, ng_post), ng_params in synaptic_params.items():
s = manyTargets(ng_pre.name)
model = uxhwModel + '\n' + s
print(model)
#synapse_equation = f'Isyn_{ng_post.name}_post = I_{ng_pre.name} : amp (summed)'
# print(model)
# we need u+*x- for the on_pre with u+ being the u value after the synaptic spike and x- being the variable before the spike
s = Synapses(ng_pre, ng_post, model = model, method = 'euler',
on_pre = {'pre_1' : f'I_{ng_pre.name} -= 1 * mamp',
'pre_2' : 'u_syn += U * (1 -u_syn)',
'pre_3' : 'u_plus = u_syn + U * (1-u_syn)',
'pre_4' : 'x -= u_plus * x'}, on_event ={'pre_1' : 'spike', 'pre_2' : 'spike', 'pre_3' : 'spike', 'pre_4' : 'spike'},
delay = {'pre_1' : (np.random.rand() * (ng_params.get('delayer') - 1) + 1) * ms,
'pre_2' :  (np.random.rand() * (ng_params.get('delayer') - 1) + 1) * ms,
'pre_3' :  (np.random.rand() * (ng_params.get('delayer') - 1) + 1) * ms,
'pre_4' :  (np.random.rand() * (ng_params.get('delayer') - 1) + 1) * ms},
name = f"{ng_pre.name}_{ng_post.name}_synapse", namespace = ng_params)
s.connect(condition = 'i!=j', p = ng_params.get('p', None))
ng_params.get('wm')
s.w = ((np.random.uniform(ng_params.get('wl', None), ng_params.get('wm', None))
+ np.random.uniform(ng_params.get('wm'), ng_params.get('wu')))/2) * mV
x = getattr(s, f'I_{ng_pre.name}')
print(x)
setattr(ng_post, f'Isyn_{ng_post.name}', x)
print("s.equations: ", s.equations)
print("ng_pre's name: ", ng_pre.name)
print("ng_post's name: ", ng_post.name)
print("ng_params is: ", ng_params)
num_synapse.append(s)
##ng_key[0].IsynVals[IsynVals.index(ng_key[1].name)] = currentArray[currentArray.index(ng_key[0].name)]
return num_synapse, num_group

def create_synapse():
_create_Neurons()
num_Synapse, num_group = group_synapse()
return num_Synapse, num_group
``````

# Full traceback of error (if relevant)

``````setattr(ng_post, f'Isyn_{ng_post.name}', x)
File "/opt/homebrew/lib/python3.11/site-packages/brian2/core/variables.py", line 1325, in set_with_index_array
variable.get_value()[indices] = value
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
ValueError: could not broadcast input array from shape (12,) into shape (20,)
``````

Hi @spoma33. I have to say I do not quite understand what you want to do, do you want to use a “summed variable”, i.e. in the post-synaptic neuron, sum up a number of currents from the synapses? In that case, you’d need to use the respective syntax: Synapses — Brian 2 2.6.0 documentation

When you assign something like `ng_post.Isyn_something = s.I_something` (or the equivalent via `getattr`/`setattr`), you are setting initial conditions for a variable. I.e., you are asking to set the initial value of `Isyn_something` to the current value of `I_something`. In your case, this fails because `Isyn_something` is a vector with 20 values, whereas `I_something` is a vector with only 12 values. (As a minor remark: when we talk in Brian about “Dimension mismatch errors”, we refer to physical dimensions, i.e. errors such as trying to add a value in seconds to a value in volts – you are dealing with what we’d call a “shape mismatch error” here).

Hope that helps, if not, please clarify a bit what you want to do.

PS: This is unrelated to your question, but do you really want to execute your `pre_...` pathways at random times and therefore in random order…?