problems on assigning value to a 3D array and print it out,thx:)

D

dd

Hi, I have the following code and want to assign value to a 3D arrays
and print it out. But it seems that the value 1 hasn't been assigned to
that array.

Could anyone help me out? Thank you very much!
int ***alloc3d( int dim1, int dim2, int dim3)
{
int i,j;
int ***base=(int ***)malloc(sizeof(int**)*dim1);
for(i=0;i<dim1;i++)
{
base=(int **)malloc(sizeof(int*)*dim2);
for(j=0;j<dim2;j++)
base[j]=(int *)malloc(sizeof(int)*dim3);
}
return base;
}

snn.weights=alloc3d(len_delay+1, sum_neurons+1, sum_neurons+1);
for (h=1;h<=len_delay;h++){
neuron_index=1;
for (i=1;i<=snn.num_layers;i++)

for (j=1;j<=snn.neurons_per_layer;j++){
for(k=1;k<=snn.neurons_per_layer[i+1];k++){
for (sumtemp=0,temp=0;temp<=i;temp++)
{
sumtemp=sumtemp+snn.neurons_per_layer[temp];
}
snn.weights[h][neuron_index][sumtemp+k]=1;

}
neuron_index=neuron_index+1;
}

void print_SNN(SNN *psnn) {
#ifdef printweights

len_delay=ceil((psnn->delay_range[2]-psnn->delay_range[0])/psnn->delay_range[1]);

for (h=1;h<=len_delay;h++){
for (i=1;i<=psnn->num_layers;i++)
for (j=1;j<=psnn->neurons_per_layer;j++){

printf("\n h, %d, i, %d, j, %d, weights %f \n", h,i,j,
psnn->weights[h][j]);


}

}
#endif
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top