Some data to play with. The matrix `amat` has row vectors that represent the OP's vectors `a[i]`. We can use `amat[[i]]` in place of `a[i]`.
In[]:=
(*Exampledata*)​​​​(*asmallernumberthan1080*)​​nmax=5;​​(*5x8matrix:5rowvectorsoflength8,eachaPartofaa*)​​SeedRandom[0];(*forreproducibility*)​​amat=RandomInteger[1,{nmax,8}];​​(*a[1],...,a[5]:5vectorsoflength8,eachwithitsownreference*)​​Do[a[i]=amat[[i]],{i,nmax}]
The OP's secondary problem posted today. The variable `zz` represents the OP's `ZZ` vector.
zz=Array[z,8]
Out[]=
{z[1],z[2],z[3],z[4],z[5],z[6],z[7],z[8]}
{Total[amat.zz]​​,Sum[zz.a[i],{i,nmax}](*OP'scode*)​​,Sum[zz.amat[[i]],{i,nmax}]}(*amat[[i]]insteadofa[i]*)​​%//Differences(*allthreearethesame*)
Out[]=
{2z[1]+2z[2]+3z[3]+2z[4]+2z[5]+z[6]+z[7]+2z[8],2z[1]+2z[2]+3z[3]+2z[4]+2z[5]+z[6]+z[7]+2z[8],2z[1]+2z[2]+3z[3]+2z[4]+2z[5]+z[6]+z[7]+2z[8]}
Out[]=
{0,0}
The following solves the problem in the original post:
Do[amat[[i,i]]=2,{i,Min[nmax,8]}]​​amat//MatrixForm
Out[]//MatrixForm=
2
0
1
0
0
1
1
1
0
2
0
0
1
0
0
0
0
0
2
0
0
0
0
1
0
1
0
2
1
0
0
0
1
1
1
1
2
0
0
0